python tkinter example code

纯净搜索 为您找到 本页 3 条,用时 5.99 秒(数据源:360)

AI 回答 由 glm-4-flash 生成 · 仅供参考,请自行核实
1. 创建主窗口

import tkinter as tk
root = tk.Tk()
root.title("Tkinter Example")

2. 添加标签

label = tk.Label(root, text="Hello, Tkinter!")
label.pack()

3. 添加按钮

def on_button_click():
label.config(text="Button Clicked!")

button = tk.Button(root, text="Click Me", command=on_button_click)
button.pack()

4. 启动事件循环

root.mainloop()