Skip to content

Commit f63c854

Browse files
committed
add gui app sample
1 parent 1e1333b commit f63c854

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

py3/gui/hello_gui.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
from tkinter import *
5+
import tkinter.messagebox as messagebox
6+
7+
class Application(Frame):
8+
def __init__(self, master=None):
9+
Frame.__init__(self, master)
10+
self.pack()
11+
self.createWidgets()
12+
13+
def createWidgets(self):
14+
self.nameInput = Entry(self)
15+
self.nameInput.pack()
16+
self.alertButton = Button(self, text='Hello', command=self.hello)
17+
self.alertButton.pack()
18+
19+
def hello(self):
20+
name = self.nameInput.get() or 'world'
21+
messagebox.showinfo('Message', 'Hello, %s' % name)
22+
23+
app = Application()
24+
# 设置窗口标题:
25+
app.master.title('Hello World')
26+
# 主消息循环:
27+
app.mainloop()

0 commit comments

Comments
 (0)