Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hiding a progressbar in tkinter

263 views
Skip to first unread message

Cecil Westerhof

unread,
Jun 26, 2019, 11:59:16 AM6/26/19
to
I just started with GUI stuff in tkinter. I have a progressbar, but I
want it to be only visible when it is used. So I tried the following:
window = Tk()
window.title(window_str)
frame = Frame(window)
frame.pack(side = "top", fill = "both", expand = True)
Button(window, text = button_str, command = select_dir).pack()
progress = ttk.Progressbar(window, orient = "horizontal", length = 200,
mode = "determinate")
progress.pack()
progress.lower(frame)
window.mainloop()

But that does not hide the progressbar. What am I doing wrong?

I could use pack_forget, but that will change the dimensions of the
window.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Wildman

unread,
Jun 26, 2019, 2:21:29 PM6/26/19
to
On Wed, 26 Jun 2019 17:47:39 +0200, Cecil Westerhof wrote:

> I just started with GUI stuff in tkinter. I have a progressbar, but I
> want it to be only visible when it is used. So I tried the following:
> window = Tk()
> window.title(window_str)
> frame = Frame(window)
> frame.pack(side = "top", fill = "both", expand = True)
> Button(window, text = button_str, command = select_dir).pack()
> progress = ttk.Progressbar(window, orient = "horizontal", length = 200,
> mode = "determinate")
> progress.pack()
> progress.lower(frame)
> window.mainloop()
>
> But that does not hide the progressbar. What am I doing wrong?
>
> I could use pack_forget, but that will change the dimensions of the
> window.

Here is an example using grid_forget().

https://stackoverflow.com/questions/33768577/tkinter-gui-with-progress-bar

Disclaimer: I have not tested this code and cannot say for certain
that it will work the way you want.

--
<Wildman> GNU/Linux user #557453
"Be vewy vewy qwiwet, I'm hunting wabbits."
-Elmer Fudd

MRAB

unread,
Jun 26, 2019, 2:59:06 PM6/26/19
to
On 2019-06-26 16:47, Cecil Westerhof wrote:
> I just started with GUI stuff in tkinter. I have a progressbar, but I
> want it to be only visible when it is used. So I tried the following:
> window = Tk()
> window.title(window_str)
> frame = Frame(window)
> frame.pack(side = "top", fill = "both", expand = True)
> Button(window, text = button_str, command = select_dir).pack()
> progress = ttk.Progressbar(window, orient = "horizontal", length = 200,
> mode = "determinate")
> progress.pack()
> progress.lower(frame)
> window.mainloop()
>
> But that does not hide the progressbar. What am I doing wrong?
>
> I could use pack_forget, but that will change the dimensions of the
> window.
>
The progress bar isn't hidden because there's nothing on top of it to
hide it.

import tkinter as tk
import tkinter.ttk as ttk

window = tk.Tk()
window.title(window_str)
frame = tk.Frame(window)
frame.pack(side='top', fill='both', expand=True)
tk.Button(window, text=button_str, command=select_dir).pack()

# Create a frame to hold the progress bar.
progress_frame = tk.Frame(window)
progress_frame.pack(fill='x', expand=True)

# Put the progress bar into the progress frame, ensuring that it fills
the grid cell.
progress = ttk.Progressbar(progress_frame, orient='horizontal',
length=200, mode='determinate')
progress.grid(row=0, column=0, sticky='nsew')

# Now put a blank frame into the progress frame over the progress bar,
ensuring that it fills the same grid cell.
blank = tk.Frame(progress_frame)
blank.grid(row=0, column=0, sticky='nsew')

# Raise the progress bar over the blank frame to reveal it.
progress.tkraise()

# Lower the progress bar underneath the blank frame to hide it.
progress.lower()

window.mainloop()

Cecil Westerhof

unread,
Jun 28, 2019, 6:14:17 AM6/28/19
to
Works like a charm. Thanks.
0 new messages