1from tkinter import *
2
3wow = Tk()
4
5def ree(hi):
6 print(hi)
7
8w = Button ( master=wow, command=ree('hi'), text="hi" )
9
10Output:
11 Tkinter:
12 ______
13 [ hi ] <--- Button
14 ------
15
16 Shell:
17 hi <--- on button pressed
1from tkinter import *
2
3
4master = Tk()
5
6#program you want the button to execute
7def closewindow():
8 exit()
9
10#set up button
11button = Button(master, text="close window", command=closewindow)
12
13button.pack()
14
15mainloop()
16
1import Tkinter
2import tkMessageBox
3
4top = Tkinter.Tk()
5
6def helloCallBack():
7 tkMessageBox.showinfo( "Hello Python", "Hello World")
8
9B = Tkinter.Button(top, text ="Hello", command = helloCallBack)
10
11B.pack()
12top.mainloop()