使用tkinter来开发GUI应用
时间: 2023-02-24 20:11:24 浏览: 144
Tkinter是一个用于开发图形用户界面(GUI)应用程序的标准库,它可以帮助开发者快速地创建各种类型的界面,如窗口、对话框、按钮、文本框等。
使用Tkinter,开发者可以创建主窗口,并在其中添加各种组件,通过设置属性和绑定事件处理器来控制组件的外观和行为。
下面是一个简单的Tkinter程序的例子,该程序创建了一个带有按钮的窗口:
```
import tkinter as tk
def on_button_click():
print("Button clicked")
root = tk.Tk()
button = tk.Button(root, text="Click me!", command=on_button_click)
button.pack()
root.mainloop()
```
该程序创建了一个名为root的主窗口,并在其中创建了一个名为button的按钮。当用户单击按钮时,会调用`on_button_click`函数,该函数将打印"Button clicked"消息。