如何检查按钮是否有效
how to check the button works
我知道“ip”有效,但是当我点击按钮时,我什么也看不到(用户应该什么也看不到,所以这太棒了!)但是,我不知道如何验证按钮的能力.
目标是最终将指定的信息从按钮发送到标签小部件(用户将看到)
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 函数正常工作,它将 运行!
我知道“ip”有效,但是当我点击按钮时,我什么也看不到(用户应该什么也看不到,所以这太棒了!)但是,我不知道如何验证按钮的能力. 目标是最终将指定的信息从按钮发送到标签小部件(用户将看到)
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 函数正常工作,它将 运行!