An electronic device comprising: a housing; a display visible through a part of the housing; at least one wireless communication circuit disposed inside the housing and configured to be wirelessly connected to a pen that provides a button event; a processor disposed inside the housing and operatively connected to the display and the at least one wireless communication circuit; and a memory disposed inside the housing and operatively connected to the processor, the memory being configured to store an application program including a user interface for selecting at least one function, and to store instructions that when executed cause the processor to display the user interface on the display; in response to the button event, provide, on the user interface, visual information indicating the at least one function that can be mapped to the button event; at least partially receive, through the at least one wireless communication circuit, a first user input for selecting one function among the at least one function while a button of the pen is pressed and the user interface is displayed on the display; select the function selected by the first user input among the at least one function on the user interface while the button of the pen is pressed; map the selected function to the button event and store the selected function in the memory, in response to the first user input; and perform, after the selected function is stored, the mapped function in response to a detection of the button event. a housing; a display visible through a part of the housing; at least one wireless communication circuit disposed inside the housing and configured to be wirelessly connected to a pen that provides a button event; a processor disposed inside the housing and operatively connected to the display and the at least one wireless communication circuit; and a memory disposed inside the housing and operatively connected to the processor, the memory being configured to store an application program including a user interface for selecting at least one function, and to store instructions that when executed cause the processor to display the user interface on the display; in response to the button event, provide, on the user interface, visual information indicating the at least one function that can be mapped to the button event; at least partially receive, through the at least one wireless communication circuit, a first user input for selecting one function among the at least one function while a button of the pen is pressed and the user interface is displayed on the display; select the function selected by the first user input among the at least one function on the user interface while the button of the pen is pressed; map the selected function to the button event and store the selected function in the memory, in response to the first user input; and perform, after the selected function is stored, the mapped function in response to a detection of the button event. display the user interface on the display; in response to the button event, provide, on the user interface, visual information indicating the at least one function that can be mapped to the button event; at least partially receive, through the at least one wireless communication circuit, a first user input for selecting one function among the at least one function while a button of the pen is pressed and the user interface is displayed on the display; select the function selected by the first user input among the at least one function on the user interface while the button of the pen is pressed; map the selected function to the button event and store the selected function in the memory, in response to the first user input; and perform, after the selected function is stored, the mapped function in response to a detection of the button event.