我知道“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)
uj5u.com熱心網友回復:
只需快速將命令更改為不同的功能即可測驗命令!
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 功能正在運行,它將運行!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/330668.html
