Skip to content

Commit 4820d68

Browse files
committed
add GUI examples
1 parent e2dec96 commit 4820d68

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

gui/hello_world.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
'a hello world GUI example.'
5+
6+
from Tkinter import *
7+
8+
class Application(Frame):
9+
def __init__(self, master=None):
10+
Frame.__init__(self, master)
11+
self.pack()
12+
self.createWidgets()
13+
14+
def createWidgets(self):
15+
self.helloLabel = Label(self, text='Hello, world!')
16+
self.helloLabel.pack()
17+
self.quitButton = Button(self, text='Quit', command=self.quit)
18+
self.quitButton.pack()
19+
20+
app = Application()
21+
# 窗口标题:
22+
app.master.title('Hello World')
23+
# 主消息循环:
24+
app.mainloop()

gui/input.py

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

0 commit comments

Comments
 (0)