要在Python窗口上添加按钮,您需要使用GUI框架。以下是使用Tkinter库添加一个按钮的示例代码:

import tkinter as tk

root = tk.Tk()

def button_click():
    print('Button clicked')

button = tk.Button(root, text='Click me!', command=button_click)
button.pack()

root.mainloop()

这将创建一个带有一个按钮的窗口。当用户单击按钮时,消息'Button clicked'将打印到控制台。您可以根据需要更改按钮的文本和命令函数。

如何在Python窗口上添加按钮 - 使用Tkinter库

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

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