Open Pin-Jiun opened 1 year ago
Boolean() 布林值變數,True是1, False是0 DoubleVar() 浮點數,預設值為 0.0 IntVar() 整數,預設值為 0 StringVar() 字串,預設值為空字串" "
from tkinter import *
root=Tk()
def method2():
x="Done it !"
m.set(x)
m=StringVar()
b1=Button(root, text="Click", command=method2).pack()
lb1=Label(root, text="...", textvariable=m).pack()
root.mainloop()
When a user hits the button on the Tkinter Button widget, the command option is activated. In some situations, it’s necessary to supply parameters to the connected command function.
Method 1: Pass Arguments to Tkinter Button using the lambda function
Import the Tkinter package and create a root window. Give the root window a title(using title()) and dimension(using geometry()), now Create a button using (Button()). Use mainloop() to call the endless loop of the window. lambda function creates a temporary simple function to be called when the Button is clicked.
Method 2: Pass Arguments to Tkinter Button using partial
Import the Tkinter package and create a root window. Give the root window a title(using title()) and dimension(using geometry()), now Create a button using (Button()). Use mainloop() to call the endless loop of the window. command=partial returns a callable object that behaves like a func when it is called.
https://www.geeksforgeeks.org/how-to-pass-arguments-to-tkinter-button-command/