0

(Thanks in advance if you decide to answer. Sorry If I am not able to describe the content of the Application clearly.)

I am currently making Desktop Application using Tkinter Python for my gui interface. I am having a problem related to the flow of the Application.

My Application

Main Page of my application has form designed with some textboxes and checkboxes. Check button work as True or False Condition, where each check button refers to whether or not a specific function has to be executed or not. To store the values of the check button, the dictionary is maintained with keys as LabelName and values as True/False value.

Checkbox code

f1=tk.BoolVar()               #People tend to use IntVar() but i prefer BoolVar()
ttk.Label(text="func1")
ttk.Checkbutton(parent, variable=f1)
f2=tk.BoolVar()               
ttk.Label(text="func2")
ttk.Checkbutton(parent, variable=f2)
-------other such CheckButtons------------------

There's a submit button in the form on pressing which all the data entered into textbox along with these check buttons. Based on true-false values, functions are called which is handled by if-else conditions.

#submit button
ttk.Button(parent,text="Submit",command=onsubmit)
###########
def onsubmit():
    ----------statements to read data--------------
    dict['func1']=f1
    dict['func2']=f2
    #other statements
    -----------------------------------------------
    if dict['func1']:
        func1()
    if dict['func2']:
        func2()
    ---other if-else conditions---

Each function is individual module which consists of either form, or frame with data or matplotlib graphs for visualization of data and to do other operations on data and graphs which are placed on root window frame.

My problem

I want the user to control the flow by giving them the next button after every function is executed and then move onto the execution of the next function based on his input of the check button. The program should wait until the User presses the next button and after they press the next button, it should execute the next function and then wait again for the next button.

One of the solution: Using fig.waitforbuttonpress() was the solution. But I didn't find it reliable. Because even mouse click could skip the function execution. But I need to specifically assign a button through which the user can select when to proceed to the next function.

  • 1
    Read [Switch between frames: `create=>hide=>tkraise()`](https://stackoverflow.com/a/7557028/7414759) and [Switch between frames:`create=>use=>destroy()`](https://stackoverflow.com/a/49325719/7414759) – stovfl Feb 05 '20 at 08:14

1 Answers1

0

I am not sure if I understood what your code does, but you could do it something like that I guess:

next_button = ttk.Button(parent,text="Next",command=func1)

...

def func1():
    #do your stuff here        
    next_button.configure(command=func2)

Then you would have to add the last line of code to all the functions to always reassign the button.

Another way could be:

process = 0

next_button = ttk.Button(parent,text="Next",command=next)

def next():
    global process
    process += 1
    if process == 1:
        func1()
    elif process == 2:
        func2()

    ...

    elif *last_function_reached*:
        process = 0
sxeros
  • 668
  • 6
  • 21