例1:创建按钮
import tkinter as tk class App: def __init__(self,root): frame = tk.Frame(root) frame.pack() self.hi_there = tk.Button(frame,text='hello',fg='blue', command=self.say_hi) self.hi_there.pack(side=tk.LEFT) def say_hi(self): print("大家好") root = tk.Tk() app = App(root) root.mainloop()
例2:
1 import tkinter as tk 2 3 T = [1,2,3] 4 class App: 5 def __init__(self,root): 6 frame = tk.Frame(root) 7 frame.pack() 8 self.hi_there = tk.Button(frame,text='hello',fg='blue',command=lambda:self.say_hi(T)) 9 self.hi_there.pack(side=tk.LEFT) 10 def say_hi(self,t): 11 t.append(4) 12 print(t) 13 14 root = tk.Tk() 15 app = App(root) 16 root.mainloop()
参考:
https://www.cnblogs.com/shwee/p/9427975.html
https://blog.csdn.net/vevenlcf/article/details/82226531
http://www.17python.com/blog/23