-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTkinterGUI.py
More file actions
27 lines (23 loc) · 798 Bytes
/
TkinterGUI.py
File metadata and controls
27 lines (23 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tkinter as tk
class Application(tk.Frame):
#初始化成员函数
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
#创建button函数
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello World\n(click me)"
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
#控制台做出反应
def say_hi(self):
print("hi there, everyone!")
root = tk.Tk()
app = Application(master=root)
app.mainloop()