Home>
There are buttons A to E, and what I want to achieve is to write the code briefly below.
Press the A button to insert A into self.master.txt_dumy and
I want to insert B into self.master.txt_dumy when I press the B button.
I tried to create command = self.btn_click in self.master.btn_1 using the btn_click function.
With this method, you have to create another function for B to E that does the same processing.
If possible, I would like to realize it with one function, but is there a good way?
def btn_click (self):
abc = self.master.btn_1 ['text']
self.master.txt_dumy.insert (tk.END, abc)
self.master.btn_1 = tkinter.Button (self.master, text ='A', font = font2, bg = "# faefe6", height = 2, width = 10, command = btn_click)
self.master.btn_1.place (x = 550, y = 50)
self.master.btn_2 = tkinter.Button (self.master, text ='B', font = font2, bg = "# faefe6", height = 2, width = 10)
self.master.btn_2.place (x = 550, y = 100)
self.master.btn_3 = tkinter.Button (self.master, text ='C', font = font2, bg = "# faefe6", height = 2, width = 10)
self.master.btn_3.place (x = 550, y = 150)
self.master.btn_4 = tkinter.Button (self.master, text ='D', font = font2, bg = "# faefe6", height = 2, width = 10)
self.master.btn_4.place (x = 450, y = 100)
self.master.btn_5 = tkinter.Button (self.master, text ='E', font = font2, bg = "# faefe6", height = 2, width = 10)
self.master.btn_5.place (x = 650, y = 100)
-
Answer # 1
Related articles
- i don't know how to write python
- i don't know how to write [python requests module] corresponding to [curl -f hoge = ・ ・]
- i want to output the entry result of tkinter with python
- python - pltshow does not run unless you close the tkinter window
- please tell me how to write a program to end when the result is executed 5 times [python]
- python 3x - python3 tkinter treeview data update
- python 3x - python3 tkinter no response when closing window
- python - [tkinter] multiple selectable combobox
- [python] i want to interweave character strings and data with write () of file writing
- c ++ - i want to write the required expression concisely
- python - django form i want to write a little smarter
- python 3x - button execution action in tkinter when executing code
- where to write timesleep in python scraping
- python - i want to implement scrolled text in tkinter
- python - i want to buy a tkinter button layout
- i don't know how to write a generator (python)
- python 3x - i want to extract data from a python3 tkinter list
- [python] [tkinter] i want to get multiple checkbox values
- python - how to make a table in tkinter
Related questions
- about image display of python
- [python] [tkinter] i want to change the acquisition contents of the second and subsequent menu lists by selecting the previous p
- python - i want to implement scrolled text in tkinter
- python 3x - button execution action in tkinter when executing code
- matplotlib - the image of matplot is displayed on the gui of tkinter, but i want to display the histogram in a separate window
- python 3x - python3 tkinter no response when closing window
- python - i want to display the next window when i press the button!
- i want to display screens with different window sizes when i press the [python/tkinter] tab
- python 3x - python3 tkinter treeview data update
- [python3] i want to scroll the screen after screen transition
If you register an event handler with bind,
Of the argument
event.widget
You can browse your own widget withAnother way: bind arguments with functools.partial
When registering with command, there is no argument, but if you use functools.partial
Unlike bind, you can bind any number of arguments.
However, since an object that associates the function and the argument is created for each button,
For brevity, it's better to use bind (if possible).
NG: CANNOT ... No instance was created at the time of registering command in the constructor
Other method 2: Use subclasses
General-purpose solution using classes