-1

I have the following example code:

class A():
    def foo(self):

        def onButtonPress():
            progress.grid()
            progress.start()

        progress = ttk.Progressbar(
            root,
            orient="horizontal"
            mode="indeterminate")

        progress.grid(
            row=3,
            column=0,
            columnspan=2,
            sticky="nswe")

        # Make it invisible at first
        progress.grid_forget()

When I run it, it's invisible at first, but once started, the grid is forgotten meaning it's just thrown in without the formatting. I replace the grid() command in onButtonPress with the same code, it works and fills out the columns. I was following this solution. Any ideas what's wrong?

Edit: Rookie mistake, was using grid_forget instead of grid_remove. grid_remove fixed it all.

Community
  • 1
  • 1
user3000724
  • 651
  • 3
  • 11
  • 22
  • Is that your real code? You seem to be missing a parenthesis after `ttk.Progressbar`. Also, this sentence seems to make no sense: "the grid is forgotten meaning it's just thrown in without formatting". How can it be both forgotten and "thrown in"? – Bryan Oakley Mar 17 '16 at 18:41
  • I should clarify this is not cut and paste, my code is very long and this is an example of how it's structured. Everything runs fine, just I have to paste the entire grid command with details if I want it to work in the embedded class. The grid forgets the layout and it just pastes it at the bottom of my GUI where it's not stickied – user3000724 Mar 17 '16 at 18:44
  • None of that matters. The only thing that matters is that the code you post actually gives the error or bad behavior that you are asking about. The code is useless if it isn't actual code that is directly related to the problem. – Bryan Oakley Mar 17 '16 at 18:49

2 Answers2

0

I'm not to familiar with tkinter, but there is a syntax error here.

progress = ttk.Progressbar( #forgot to open parenthesis 
            root,
            orient="horizontal", #need another comma
            mode="indeterminate")
Tony
  • 1,318
  • 1
  • 14
  • 36
  • Sorry about the syntax error, this is just an example of how it's structured. A function in a class with another function inside, and grid_forget isn't doing what I expect it to do. I have to reenter the row,column,sticky inside the embedded function for it to work. – user3000724 Mar 17 '16 at 18:45
0

To answer this old posting, the mistake is you used grid_forget() when the method you really want is grid_remove(). The former will literally forget all configuration, while the latter just hides the widget (retaining all configuration). So with the latter, when you do a grid(), the widget appears again with its previous settings intact.

dotw
  • 99
  • 9