如何检查按钮工作



我知道"工作,但当我去点击按钮,我什么也没看到(用户应该看到什么,所以这是伟大的!)然而,我不知道我如何验证按钮的能力。目标是最终将指定的信息从按钮发送到标签小部件(用户将看到)

import tkinter as tk
import subprocess

ip = subprocess.run("ipconfig /all",universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

#Setup for the window
window =tk.Tk()
window.title("Title_Name")
window.geometry("300x500")
x = window.winfo_x()
y = window.winfo_y()
sh = window.winfo_screenheight()
sw = window.winfo_screenwidth()
x_cord = int((sw/2)-550)
y_cord = int((sh/2)-300)
wh = 350
ww = 500
window.geometry("{}x{}+{}+{}".format(ww, wh ,x_cord, y_cord))

#widgets
button = tk.Button(window, text= "submit",
command = ip)
#widget placement
button.grid(row=0, column=0, padx=5)

只需快速更改命令到不同的功能来测试命令!

import tkinter as tk
import subprocess

ip = subprocess.run("ipconfig /all",universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

#Setup for the window
window =tk.Tk()
window.title("Title_Name")
window.geometry("300x500")
x = window.winfo_x()
y = window.winfo_y()
sh = window.winfo_screenheight()
sw = window.winfo_screenwidth()
x_cord = int((sw/2)-550)
y_cord = int((sh/2)-300)
wh = 350
ww = 500
window.geometry("{}x{}+{}+{}".format(ww, wh ,x_cord, y_cord))
def ButtonTest():
print('The button is working!')
#widgets
button = tk.Button(window, text= "submit",
command = ButtonTest)
#widget placement
button.grid(row=0, column=0, padx=5)
tk.mainloop()

当您运行此代码并按下按钮时,它将打印输出,因此您可以放心,假设ip函数正在工作,它将运行!

最新更新