File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments