图形界面

Python支持多种图形界面的第三方库,包括:

Tk

wxWidgets

Qt

GTK


使用tk

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
'图形界面'
from tkinter import *
import tkinter.messagebox as messagebox
class (Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.helloLabel = Label(self, text='Hello World')
self.helloLabel.pack()
self.quitButton = Button(self, text='Quit', command=self.quit)
self.quitButton.pack()
self.nameInput = Entry(self)
self.nameInput.pack()
self.alertButton = Button(self,text='发送',command = self.hello)
self.alertButton.pack()
def hello(self):
name = self.nameInput.get() or 'world'
messagebox.showinfo('Message','Hello, %s'%name)
app = Applicaction()
# 设置标题
app.master.title('Hello World')
# 主消息循环
app.mainloop()