Python Tkinter while循环未停止 使用步进电机打开和关闭空间加热器旋钮的程序
#从用户处获取输入(当前未使用,正在尝试设置GUI) #安排加热器的开启时间Python Tkinter while循环未停止 使用步进电机打开和关闭空间加热器旋钮的程序,python,python-2.7,tkinter,Python,Python 2.7,Tkinter,#从用户处获取输入(当前未使用,正在尝试设置GUI) #安排加热器的开启时间 def SaveMarker(state): fileobject=open(filename, 'wb') pickle.dump(marker,fileobject) fileobject.close() print ("marker saved, Goodbye!!!") #电机转动代码 class Application(Frame): """ A GUI applic
def SaveMarker(state):
fileobject=open(filename, 'wb')
pickle.dump(marker,fileobject)
fileobject.close()
print ("marker saved, Goodbye!!!")
#电机转动代码
class Application(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
"""initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text= marker )
self.instruction.grid(row=0, column=0, columnspan=2, sticky=W)
self.userinput= Entry(`enter code here`self)
self.userinput.grid(row=1, column=1, sticky=W)
self.submit_button=Button(self, text= "Submit", command=self.reveal)
self.submit_button.grid(row=2, column=0, sticky=W)
self.text= Text(self, width=35, height=5, wrap=WORD)
self.text.grid(row=3, column=0, columnspan=2, sticky=W)
def reveal(self):
stepper=self.userinput.get()
帮助这个while循环以某种方式结束了无限????????????这里没有。它在Tkinter之外工作。我真的复制并粘贴了代码,在点击提交按钮后,它会永远执行,电机会一直转动,不会停止。当步进器=标记正确时,它应该断开?
whilestepper=标记:
打印步进计数器,
打印顺序[步进计数器],“步进器:,(步进器),“标记器:,(标记器)
如果(步进器=步数):
步进计数器=0
如果(StepCounter看起来像是步进器
应该转换成数值,可能是int
:
while stepper!=marker:
print StepCounter,
print Seq[StepCounter], "stepper: ", (stepper), "Marker: ", (marker)
if (stepper<marker):
stepDir=-1
else:
stepDir=1
for pin in range(0, 4):
xpin = StepPins[pin]
if Seq[StepCounter][pin]!=0:
GPIO.output(xpin, True)
else:
GPIO.output(xpin, False)
marker+=stepDir
StepCounter += stepDir
# If we reach the end of the sequence
# start again
if (StepCounter>=StepCount):
StepCounter = 0
if (StepCounter<0):
StepCounter = StepCount+stepDir
# Wait before moving on
time.sleep(.006)
for pin in StepPins:
GPIO.output(pin, False)
SaveMarker(marker)
if content == marker:
message = "content" + str(content)
else:
print "success"
message ="marker" + str(marker) +"content" + str(content)
self.text.insert(0.0, message)
root = Tk()
root.title("Passwords")
root.geometry("250x150")
app=Application(root)
root.mainloop()
# Start main loop
#Old code
#while True:
# CallInput()
# RunMotor(user)
import atexit
atexit.register(SaveMarker)
stepper=self.userinput.get()
...
而步进器!=标记器:
...
如果(Stepher)您发布的代码太多。请将代码减少到a,然后显示您为调试此代码所做的步骤。
def SaveMarker(state):
fileobject=open(filename, 'wb')
pickle.dump(marker,fileobject)
fileobject.close()
print ("marker saved, Goodbye!!!")
def Schedule():
import datetime
print ("hello welcome to the Scheduler!")
print ("")
CallInput()
year=2017
month=datetime.datetime.now().strftime("%m")
hour=input("please enter the hour: ")
AMPM=str(raw_input("AM or PM: "))
minute=input("please enter the minute: ")
day=input("please enter the day: ")
if (AMPM=="PM" or AMPM== "pm"):
print (AMPM)
print ("hour: ", hour)
hour+=12
print ("hour: ", hour)
print (year, " ", month, " ", day, " ", hour, " ", minute)
starttime=datetime.datetime(int(year),int(month),int(day),hour,minute)
#if (hour<int(datetime.datetime.now().strptime("%h"))
#oneday=datetime.timedelta(days=+1)
while datetime.datetime.now() <starttime:
time.sleep(1)
print("youdidit",starttime, " ", datetime.datetime.now())
print("youdidit",starttime, " ", datetime.datetime.now())
RunMotor(user)
class Application(Frame):
""" A GUI application with three buttons. """
def __init__(self, master):
"""initialize the frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text= marker )
self.instruction.grid(row=0, column=0, columnspan=2, sticky=W)
self.userinput= Entry(`enter code here`self)
self.userinput.grid(row=1, column=1, sticky=W)
self.submit_button=Button(self, text= "Submit", command=self.reveal)
self.submit_button.grid(row=2, column=0, sticky=W)
self.text= Text(self, width=35, height=5, wrap=WORD)
self.text.grid(row=3, column=0, columnspan=2, sticky=W)
def reveal(self):
stepper=self.userinput.get()
global StepCount
global StepCounter
global StepDir
global marker
while stepper!=marker:
print StepCounter,
print Seq[StepCounter], "stepper: ", (stepper), "Marker: ", (marker)
if (stepper<marker):
stepDir=-1
else:
stepDir=1
for pin in range(0, 4):
xpin = StepPins[pin]
if Seq[StepCounter][pin]!=0:
GPIO.output(xpin, True)
else:
GPIO.output(xpin, False)
marker+=stepDir
StepCounter += stepDir
# If we reach the end of the sequence
# start again
if (StepCounter>=StepCount):
StepCounter = 0
if (StepCounter<0):
StepCounter = StepCount+stepDir
# Wait before moving on
time.sleep(.006)
for pin in StepPins:
GPIO.output(pin, False)
SaveMarker(marker)
if content == marker:
message = "content" + str(content)
else:
print "success"
message ="marker" + str(marker) +"content" + str(content)
self.text.insert(0.0, message)
root = Tk()
root.title("Passwords")
root.geometry("250x150")
app=Application(root)
root.mainloop()
# Start main loop
#Old code
#while True:
# CallInput()
# RunMotor(user)
import atexit
atexit.register(SaveMarker)
stepper=self.userinput.get()
...
while stepper!=marker:
...
if (stepper<marker):
...
if content == marker:
message = "content" + str(content)