-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse_GUI.py
More file actions
51 lines (39 loc) · 1.48 KB
/
Copy pathuse_GUI.py
File metadata and controls
51 lines (39 loc) · 1.48 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/env python3
# -*- coding:utf-8 -*-
# tkinter library
from tkinter import *
# 从Frame派生,父容器
# Frame容纳Widget
# example
class Application_test(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack() # pack()加入到父容器
self.createWidgets()
def createWidgets(self):
self.helloLabel = Label(self, text='Hello, world!') # Label标签
self.helloLabel.pack() # pack()到父容器
self.quitButton = Button(self, text='Quit', command=self.quit) # Button标签
self.quitButton.pack() # pack()到父容器
app=Application_test()
app.master.title('Hello,World!') # 设置窗口标题
app.mainloop() # 主消息循环
# another example
from tkinter import *
import tkinter.messagebox as messagebox # messagebox包私有命名
class Application_test1(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.nameInput = Entry(self) # 输入框标签
self.nameInput.pack()
self.alertButton = Button(self, text='Hello', command=self.hello)
self.alertButton.pack()
def hello(self):
name = self.nameInput.get() or 'world' # 获取输入内容
messagebox.showinfo('Message', 'Hello, %s' % name) # Message对话框
app1=Application_test1()
app1.master.title(app1.nameInput.get() or 'World')
app.mainloop()