我的按钮将启动并停止从外部模块调用的功能
通过仅放置R.Loop(),该功能在GUI内调用时起作用。但是,它不会单击按钮。我尝试使用.configure,但这不起作用。该模块在源代码内部也可以单独工作。我以为我在某个地方听说TKINTER不喜欢Globals,但我不确定。
#creating a global variable for running loop
global Run
Run=False
#begin GUI CODE
main = tk.Tk()
main.title('REGENERATOR')
main.geometry('800x800')
...
#THIS IS THE CALL OF FUNCTION SETUP
running_setup=R.setup()
#Funtion to initialize the motor
def motor():
if Run(True):
R.loop()
#This is the start button
def startmotor(): #Function to start motor
global Run
Run = True
#Button_run.configure()
Button_run=Button(frame5, text="run", command=lambda:startmotor, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_run.grid(row="2", column="0")
#This is the stop button
def stopmotor():
global Run
Run = False
#Button_stop.comfigure()
Button_stop=Button(frame5, text="stop", command=lambda:stopmotor, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_stop.grid(row="2", column="1")
The function works when called inside the GUI by just placing R.loop(). However, it doesn't run with a button click. I've tried using .configure, but that doesn't work. The module works fine on its own inside the source code as well. I thought I heard somewhere that Tkinter doesn't like globals, but I'm not sure.
#creating a global variable for running loop
global Run
Run=False
#begin GUI CODE
main = tk.Tk()
main.title('REGENERATOR')
main.geometry('800x800')
...
#THIS IS THE CALL OF FUNCTION SETUP
running_setup=R.setup()
#Funtion to initialize the motor
def motor():
if Run(True):
R.loop()
#This is the start button
def startmotor(): #Function to start motor
global Run
Run = True
#Button_run.configure()
Button_run=Button(frame5, text="run", command=lambda:startmotor, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_run.grid(row="2", column="0")
#This is the stop button
def stopmotor():
global Run
Run = False
#Button_stop.comfigure()
Button_stop=Button(frame5, text="stop", command=lambda:stopmotor, bg="white", fg="black", padx=5, pady=5, font=("Times", 16))
Button_stop.grid(row="2", column="1")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论