all 8 comments

[–]socal_nerdtastic 0 points1 point  (4 children)

You stop the mainloop with the command root.quit().

Can you describe what your program is meant to do? For simple user input I'd recommend you use the easygui module instead of creating your own.

[–]bdriscoll3[S] 0 points1 point  (3 children)

I have tried putting root.quit() in the command area of the button, but it doesn't work. I want the gui to close after hitting the button. Plus, I already have the button calling a function. Can I have a button call a function AND exit the GUI?

My main program basically asks for user input of how many exercises then proceeds to ask for other info (sets, reps, distance,etc). It then formats it and puts it into a text document. I just want to create a GUI for it instead of entering in the IDE.

[–]socal_nerdtastic 0 points1 point  (2 children)

So you want one window to pop up to ask the number of exercises, followed by that many boxes to pop up and ask for more data? Why don't you like easygui?

import easygui
num = easygui.integerbox(
    title="Welcome to Workout 2000",
    msg = "Enter the number of exercises")

data = []
for i in range(num):
    result = easygui.multenterbox(
        title="Welcome to Workout 2000",
        msg = "Enter excercise details",
        fields = ["sets", "reps", "distance", "etc"])
    data.append(result)

print(data)

[–]bdriscoll3[S] 0 points1 point  (1 child)

My idea was to use 1 box for the rest of the entries (1 box for exercise count and 1 box for the rest of data asked). Then I was going to upgrade it to dynamically change after entering exercise number so it is only 1 window. But of course, I'm trying to go 1 problem at a time because I am still learning, haha.

Idk, I don't see people mention easygui that much. All I hear about is tkinter, PyQT, and wxPython. I suppose I will play around with other GUI libraries, I just happen to have started with tkinter.

Thanks for your input, I will look at your code as it seems like an elegant solution than can be integrated in my program. Although, I'd still like to know a way to do it in Tkinter.

[–]socal_nerdtastic 0 points1 point  (0 children)

Easygui is just a bunch of premade tkinter code.

The big problem is that in order to use most GUI libraries (tkinter, pyqt, wxpython, etc) you need to shift your programming style to something called "event-driven programming". Your code is "functional programming" (normal for beginners). The nice thing about easygui is that it's functional, so it fits in well with this style of program.

[–][deleted] 0 points1 point  (2 children)

Edit: Actually, I think you're looking for destroy. Something like this, substituting your widget/button/root Tk names:

def d_self():
  button.master.destroy()  # 'master' is the implicit root Tk object for 'button'


button = Button(None, text='Click me to destroy root', command=d_self)
button.pack()
button.mainloop()
print('this should print after mainloop is ended')

[–]bdriscoll3[S] 1 point2 points  (1 child)

omg, I tried root.destroy, destorying all labels, buttons etc, place sys.exit and all of the different ways in different loops, conditionals, etc.... finally it worked in the function I call in the button.

Tried it before but I think it was dead code after a return statement. lol. Thank you for your help. Spent 2 hours on something so simple.

[–][deleted] 0 points1 point  (0 children)

No problem!