1import tkinter as tk
2
3obj = tk.Tk() # Creates a tkinter object
4label = tk.Label(obj, text="This is a text button")
1import tkinter as tk
2
3class Application(tk.Frame):
4 def __init__(self, master=None):
5 super().__init__(master)
6 self.master = master
7 self.pack()
8 self.create_widgets()
9
10 def create_widgets(self):
11 self.hi_there = tk.Button(self)
12 self.hi_there["text"] = "Hello World\n(click me)"
13 self.hi_there["command"] = self.say_hi
14 self.hi_there.pack(side="top")
15
16 self.quit = tk.Button(self, text="QUIT", fg="red",
17 command=self.master.destroy)
18 self.quit.pack(side="bottom")
19
20 def say_hi(self):
21 print("hi there, everyone!")
22
23root = tk.Tk()
24app = Application(master=root)
25app.mainloop()
26