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
1def create_buttons(self):
2 for x in range(10):
3 button = ttk.Button(self, text=x, command=lambda number=x: self.callback(number))
4 button.grid()
5
1def callback(self, number):
2 new_value = self.user_input.get() + str(number)
3 self.user_input.set(new_value)
4