Python Forum
Continue command in python tkinter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Continue command in python tkinter?
#2
Anywhere you use a function you can also use a lambda expression, since a lambda expression is just a different way of writing a function. But I don't think that is what you are asking. To be honest I have no idea what you are asking.

You use the words "continue" and "def". In Python, "continue" can be used to jump to the start of an enclosed loop. Is that what you mean by "continue"?

Another common usage of "continue" is to resume. Are you asking if you can use a button as a variable length wait? Something like this:
while not button_pressed:
    pass
# Do some things that were waiting for the button press
…
Button(root, 'Push me', command=button_pressed=True)
This is wrong in a couple of ways. The first error is that you cannot have "infinite" loops in a GUI program. The "while not button_pressed:" loop prevents mainloop() from running. If mainloop() does not run then the program will not recognize that you pushed the button. The entire GUI freezes.

Since waiting is mostly done by preventing anything else from happening, waiting is something to avoid in a GUI program. A GUI program is event driven. You do not wait for the user to do anything. The user performs actions which generate events (button presses, text entry etc...) and your program responds to the events to do what the user wants to do. So instead of:
do_A()
wait for button press
do_B()
You would have something like:
do_A()
Button(root, text="Push me", command=do_B())
Instead of a long stream of code that you expect to execute sequentially your program becomes a bunch of short functions that get bound to GUI controls. It is a completely different way of thinking about programming.
Reply


Messages In This Thread
Continue command in python tkinter? - by MLGpotato - Feb-24-2021, 04:37 PM
RE: Continue command in python tkinter? - by deanhystad - Feb-24-2021, 05:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 6,193 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  [Tkinter] button command tkinter Heyjoe 6 5,377 Jul-30-2020, 07:06 PM
Last Post: deanhystad
  tkinter button not accessing the command when clicked jhf2 1 3,659 Nov-23-2019, 10:17 PM
Last Post: DT2000
  [Tkinter] Tkinter newly created button does not execute command ChipsSlave 7 6,375 Jul-25-2018, 01:01 AM
Last Post: JUANCARLOS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020