几周前我开始用Python编程。我制作了一个python程序,因此我现在用tkinter制作一个gui。 gui中的用户输入将由我已编写的python程序处理。但是当我运行我的程序并想要使用python程序中的输入字段中的值时,它不会打印条目的输入值。但是打印0,0而不是。
我收到了以下代码: 我有一个类,我用tkinter(GUI_Pump.py)为我的gui制作一个框架:
import GUI as Gui
from GUI import *
import pump as Pomp
class Pump1(tk.Frame):
p1_pump_spd1 = 0
d_p1_mtr_on = 0
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text='Test case')
label.place(x=380, y=10)
def validate(new_text):
if not new_text: # the field is being cleared
self.entered_number = 0
return True
try:
self.entered_number = int(new_text)
return True
except ValueError:
return False
def ok():
global p1_pump_spd1
p1_pump_spd1 = p1.get()
try:
p1_pump_spd1
except ValueError:
p1_pump_spd1 = 0
print(Pomp.p1_pump_spd)
vcmd = parent.register(validate)
p1 = tk.Entry(self, width=10, validate='key', validatecommand=(vcmd, '%P'))
btn_ok = tk.Button(self, text='ok', command=ok, width=2)
p1.place(x=230, y=20)
btn_ok.place(x=290, y=20)
我得到了我想要处理输入值(pump.py)的python程序
from GUI import *
import GUI_Pump as GuiP
D_MH_MTR_SP_HLIM = 1500.0
D_MH_MTR_SP_LLIM = 0.0
def fc33_limit_real(MIN, IN, MAX):
if IN <= MIN:
OUT = MIN
elif IN >= MAX:
OUT = MAX
else:
OUT = IN
return OUT
p1_spd = GuiP.Pump1.p1_pump_spd1
p1_pump_spd = fc33_limit_real(D_MH_MTR_SP_LLIM, p1_spd, D_MH_MTR_SP_HLIM)
但是如果我打印p1_pump_p1_spd,我总是得到0,0,无论我填写什么输入到输入字段。任何帮助,将不胜感激。