1import tkinter as tk
2
3
4def write_slogan():
5 print("Tkinter is easy to use!")
6
7root = tk.Tk()
8frame = tk.Frame(root)
9frame.pack()
10
11button = tk.Button(frame,
12 text="QUIT",
13 fg="red",
14 command=quit)
15button.pack(side=tk.LEFT)
16slogan = tk.Button(frame,
17 text="Hello",
18 command=write_slogan)
19slogan.pack(side=tk.LEFT)
20
21root.mainloop()
22
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()
1import tkinter
2button1 = ttk.Button(self, text="anything", command=random command)
3 button1.pack()