lawsie / guizero

A Python 3 library to allow learners to quickly and easily create GUIs.
https://lawsie.github.io/guizero
BSD 3-Clause "New" or "Revised" License
401 stars 81 forks source link

When App is created visible=False, ButtonGroup radiobutton indicators are grey, not blue #508

Open k1ffx opened 2 months ago

k1ffx commented 2 months ago

This is so minor that I hesitated to enter it here.

I calculate the position in the center of my screen after creating all the widgets. So as to avoid having the UI flash in the upper corner and them move after the calculation, I create the App widget with visible=False. After calculating and moving the UI, I do an app.show().

The current UI has a ButtonGroup widget, which works fine. The peculiarity is the selected RadioButton indicator doesn't turn blue. As best as I can tell, the only difference between "it turns blue" and "it doesn't turn blue" is starting with the App widget set to visible=False.

I dug around in the underlying Tk objects for the RadioButton to see if I could find a way to work around this, but didn't.

As I say, the program works fine. It just looks a little peculiar. If I'm actually doing something wrong, I'd appreciate someone letting me know.

Thanks -

Bruce

martinohanlon commented 2 months ago

Thanks for raising an issue.

Could you provide an small example program which reproduces this?

A screenshot would also be useful.

k1ffx commented 2 months ago

The .py source file is attached, with a filetype of .txt, so as to enable the attachment. Another peculiarity: you'll notice that I did a screenshot of the entire screen. This is on a Mac using the Mac Screenshot app. When I tried to do a screenshot of just the window for my program, as soon as Screenshot drew its window over my program's window, the selected radiobutton turned blue (!).

Thanks for having a look at this.

k1ffx_file.txt k1ffx_screenshot

lawsie commented 2 months ago

Hi @k1ffx I've just run your program (commented out the image line 24) - can I check what you mean by "doesn't turn blue"? When I ran the program, any of the options I selected looked like this:

Screenshot 2024-07-05 at 09 23 54

I also tested making one of the options selected at the start and that worked as I expected. Am I not managing to reproduce the problem or have I got confused somewhere?

(PS if you want to, you can paste code directly into an issue and put it inside backticks!)

k1ffx commented 2 months ago

Good morning, @lawsie -

Thanks for your response. And you do understand the problem and apparently cannot reproduce it. When I run the program and select one of the radiobuttons, the indicator stays grey ... it looks like the app would appear if it didn't have focus or was disabled, although neither is true.

I wonder if it's a Mac-only behavior (??). I will try it on my Linux machine a little later today.

[And, by the way, many thanks for guizero ... what a great tool!!]

lawsie commented 2 months ago

It does look like that, doesn't it. I'm using a Mac too though, and it was blue when the window had focus, but when I clicked back to VS code it was greyed out. I wonder if your terminal is somehow grabbing focus back after the code runs. Possibly Martin has some ideas.

k1ffx commented 2 months ago

The Linux test wasn't helpful, because the indicator for the selected RadioButton there doesn't turn blue in any case.

Next test (back on the Mac) was to do a minimal test ... in this case, I used the cheese, ham, and salad program from the ButtonGroup page. I saw the same behavior ... grey indicator when App visible == False. However, following on your "focus" hint, I found that if I clicked out of the program window, and then clicked back in the program window, the indicator in fact turned blue.

I tried doing a choice.focus(), but that didn't help.

I then tried what has been my go-to workaround (I know ... probably not ideal programming practice), and added a app.tk.update_idletasks() after the app.show(), and that fixed the problem.

I don't know if that's an appropriate fix or workaround. Please do let me know if there's anything else I should be trying.

Thanks!