以下是一个简单的 Python Tkinter GUI 应用程序示例:

from tkinter import *
from tkinter import messagebox

# 定义窗口
root = Tk()
root.title('Python GUI Application')

# 定义标签
label1 = Label(root, text='Welcome to Python GUI Application!', font=('Arial', 18))
label1.pack()

# 定义按钮事件处理程序
def on_click():
    messagebox.showinfo('Python GUI Application', 'Hello World!')

# 定义按钮
button1 = Button(root, text='Click Me!', command=on_click)
button1.pack()

# 运行窗口
root.mainloop()

这个示例程序创建了一个简单的窗口,其中包含一个标签和一个按钮。当用户单击按钮时,它将触发一个消息框显示'Hello World!'的消息。该程序演示了如何使用 Python Tkinter 库创建 GUI 应用程序。

Python Tkinter GUI 应用程序制作实例:简单按钮和消息框

原文地址: https://www.cveoy.top/t/topic/nZOj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录