Search code examples
pythontkinterprogram-entry-point

Want Clarification for Program Loop (Python)


So I was wondering if someone would be able to help shed a little light for me on something I am working on in Python.

I am creating a program with a Tkinter GUI interface that interacts with a Serial device, and an ADC chip to measure voltage. I want to make sure I properly understand how I'm building the main program loop to keep everything running smoothly. I'm going to lay out how I think the program should run, if anyone has any corrections please throw them at me.

  1. Program is run, GUI Interface initializes
  2. User presses a button
  3. send signal of button through serial
  4. measure/display voltage levels
  5. periodically update voltage display
  6. if button is pressed, return to step 3

Now I know to run my Tkinter GUI I set up mainloop() as the last line of code. Now my question is simply, is that all I will need? Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?


Solution

  • Will mainloop() continually update while it waits for another button press, or will I essentially have to creatre an update method that cycles through everything until another button is pressed?

    Not all. That's why you are using tk.Tk().mainloop(). tkinter does this for you. All you are expected to do is implement the functionality that should happen when your button is pressed. tkinter will listen for the button press.