文档介绍:Python中使用Tkinter模块创建GUI程序实例
这篇文章主要介绍了Python中使用Tkinter模块创建GUI程序实例,本文给出了创建窗口、文本框、按钮等实例,需要的朋友可以参考下
使用Tkinter模块来创建简单的GUI程序。
Tkinter的Widgets有:Button、Canvas、Checkbutton、Entry、Frame、Label、Listbox、Menu、Menubutton、Message、Radiobutton、Scales、Scrollbar、TEXT、Toplevel等。
例:
复制代码代码如下:
# This program displays an empty window.
import Tkinter
def main():
main_window = ()
()
main()
例2:
复制代码代码如下:
import Tkinter
class MyGUI:
def __init__(self):
# Create the main window widget.
= ()
# Enter the Tkinter main loop.
()
# Create an instance of the MyGUI class.
my_gui = MyGUI()
例3:
复制代码代码如下:
# The program displays a label with text.
import Tkinter
class MyGUI:
def __init__(self):
= ()
# Create a Label widget containing the text 'Hello world'
= (, text='Hello World!')
# Call the Label widget's pack method.
()
# Enter the Tkinter main loop.
()
# Create an instance of the MyGUI class.
my_gui = MyGUI()
例4:
复制代码代码如下:
import Tkinter
class MyGUI:
def __init__(self):
= ()
= (,text='Hello World!')
= (,text='This is my GUI program.')