有没有办法让 Tkinter 中的条目在您在字段中键入时做出反应?我想要代码的“数量”部分使用此功能。
它会在单击单选按钮时自动生成 label4text,但在输入数量时不会。
from Tkinter import *
SubnetM = 0
def beenclicked():
radioValue = relStatus.get()
return
def changeLabel():
if relStatus.get() == 'HOSTS':
if custname.get() == 6:
label4Text.set("255.255.255.248")
return
if relStatus.get() == 'NETWORKS':
if custname.get() == 6:
label4Text.set("224.0.0.0")
return
app = Tk()
app.title("SUBNET MASK CALCULATOR")
app.geometry('400x450+200+200')
labelText = StringVar()
labelText.set("WELCOME!")
label1 = Label(app,textvariable=labelText, height=4)
label1.pack()
relStatus = StringVar()
relStatus.set(None)
radioValue = relStatus.get()
radio1 = Radiobutton(app, text="HOSTS", value="HOSTS", variable=relStatus, command=changeLabel)
radio1.pack()
radio1 = Radiobutton(app, text="NETWORKS", value="NETWORKS", variable=relStatus, command=changeLabel)
radio1.pack()
label2Text = StringVar()
label2Text.set("~Quantity~")
label2 = Label(app, textvariable=label2Text, height=4)
label2.pack()
custname = IntVar(None)
Quantity = Entry(app, textvariable=custname,)
Quantity.pack()
label3Text = StringVar()
label3Text.set("Your Subnet Mask is...")
label3 = Label(app, textvariable=label3Text, height=4)
label3.pack()
label4Text = StringVar()
label4Text.set(SubnetM)
label4 = Label(app, textvariable=label4Text, height=4)
label4.pack()
button1 = Button(app, text="GO!", width=20, command=changeLabel)
button1.pack(padx=15, pady=15)
app.mainloop()