TkinterEP / ttkthemes

A group of themes for the ttk extenstions for Tkinter
GNU General Public License v3.0
364 stars 47 forks source link

Get the window background dark when using a dark theme #50

Closed maicol07 closed 4 years ago

maicol07 commented 5 years ago

Hi, I've noticed that when I'm using a dark theme the window background remains grey. How can I avoid this? Also, window (Tk or toplevel) is from the base tkinter library. Thanks

EDIT: I found a working solution, using the lookup method: window.configure(bg=s.lookup("TButton", "background")) The bad thing is that you have to do this for every window you have. @RedFantom is it possible to get a list of dark themes (maybe with a method), so that I can set a white background when there is a light theme?

EDIT 2: I've also tried ThemedTk but it seems that background option doesn't work...

EDIT 3: I've fixed ThemedTk background issue with PR #51

RedFantom commented 5 years ago

What I think the real problem is here, is that ThemedTk overwrites the background keyword argument option at initialization, but it does not do the same thing for ThemedTk.config. The background option of ThemedTk is set to True, then the window automatically takes on the default background color of the theme, but a bool type is expected.

As for multiple windows, the library does not officially support using multiple Tk instances in a single program, and unless there is a very good reason to do so, it won't. Toplevels are the recommended way to use multiple windows with Tkinter, and that is supported through the toplevel kwarg.

Clearly the docstrings (and thus the documentation) are unclear in this regard, and it should be improved. Changing the keyword argument name is something I would prefer to save for another set of big changes that break backwards-compatibility. In the meantime, using the bg alias for the background option will do the trick.

RedFantom commented 5 years ago

Check out the updated documentation here, and let me know what you think.

maicol07 commented 5 years ago

I think it's OK. Toplevel is a ThemedTk argument?

RedFantom commented 5 years ago

Yes, toplevel is a keyword argument that is only available for ThemedTk, not for Tk.

maicol07 commented 5 years ago

I've found out that by doesn't work

RedFantom commented 5 years ago

Do you mean that the bg keyword argument does not work? Or something else? Because for me, using w = ThemedTk(); w.config(bg='blue') works just fine.

maicol07 commented 5 years ago

Yeah. Maybe could it be my code (PR #51) that blocks bg? (Note that background argument is working with that code)

RedFantom commented 5 years ago

How are you trying to use the background keyword argument? Because running

import tkinter as tk
w = tk.Tk(background='blue')

is supposed to raise an error. The options of a window can only be configured after it has been created.

Your code should not influence the behaviour of the bg keyword argument at all.

maicol07 commented 5 years ago

I use w = ThemedTk(background="blue") but w = ThemedTk(bg="blue") is not working

RedFantom commented 5 years ago

Using w = ThemedTk(background="blue") does not work as you expect because ThemedTk expects a bool value for background. Additionally, usingThemedTk(bg="blue")invokestk.Tk(bg="blue"), which does not work becausetk.Tk` does not accept keyword arguments upon initialization. The correct way to do it would be:

w = ThemedTk() 
w.config(background="blue")  #  OR w.config(bg="blue"), they are equal

OR

w = ThemedTk(background=True)  # Background is theme-appropriate if available
maicol07 commented 5 years ago

Ok, I've tried the code. It works well the second option, but with light themes there is the grey background that is very ugly. Also, if I use the first code, widgets' background isn't changed (while my code do this). Also, my code adapt the background to a dark theme if that is specified. Example: w = ThemedTk(background="white", theme="vista") Background will be white

w = ThemedTk(background="white", theme="equilux") Background will be equilux theme's one.

RedFantom commented 5 years ago

vista is not a theme included with ttkthemes, and therefore I cannot change the theme settings. If the background color of a theme is inconsistent with the rest of the look of the theme, then please let me know what you would prefer over in #44.

The widgets background is not changed because I do not think it is appropriate to do that from Python code. The background color of widgets should be configured in the theme settings instead, and I am open to that if the background color of the widgets is indeed inappropriate. I have not tested all themes beyond the simple example.py UI and the unit tests.

To be honest, I do not really like that approach as its behaviour is inconsistent. Instead, what I think would be ideal and clear up all confusion is to choose to change the background parameter name to something that is not used as a Tk option, then write a config and cget function modified so as to include this parameter there too, and keep this parameter a boolean value. Then, if the background option of Tk is given, then it always overrides the option the theme gives, which would result in consistent behavior.

The only way to properly introduce such a change is to use a deprecation notice (as I do not currently have major changes planned to warrant a major version bump), but I do not know when I will have time to implement such a change.

Please know that I do very much appreciate your contributions through this issue. Critical thinking helps improve this library!

RedFantom commented 5 years ago

Commit 3d74923 contains changes that fix the confusing background keyword argument and make it runtime changeable for the greatest flexibility (even though Tk does not allow changing any other keyword options. I pushed it to master in error, but I deleted that commit. That is why this issue was automatically closed. I will write some tests to make sure that everything works as it should, but the difference when running the example with the equilux theme is looking good.

ghost commented 4 years ago

Using w = ThemedTk(background="blue") does not work as you expect because ThemedTk expects a bool value for background. Additionally, usingThemedTk(bg="blue")invokestk.Tk(bg="blue"), which does not work becausetk.Tk` does not accept keyword arguments upon initialization. The correct way to do it would be:

w = ThemedTk() 
w.config(background="blue")  #  OR w.config(bg="blue"), they are equal

OR

w = ThemedTk(background=True)  # Background is theme-appropriate if available

I think you should add the background=True argument to the example on readthedocs.org. It's seems like a given that people will want the background of there program to fit in with the color of its buttons and labels, yet it doesn't by default and it took me a long time find this little pearl of wisdom. Lot's of forum posts out there of people asking for this but not knowing quite what to ask.

https://ttkthemes.readthedocs.io/en/background/example.html

So it reads this instead:

window = ThemedTk(theme="arc", background=True)

Edit: Thanks a lot for developing ttkthemes I really appreciate it. :+1:

RedFantom commented 4 years ago

@Azza-NZ Indeed, re-reading that part of the documentation definitely makes me realize that it is unclear. I did work on this before, but it never made it into the new release because actually I had hoped to finish the Materia theme before then.

In any case, I have made some changes in the themebg branch that should make the description more clear and up-to-date for the behaviour of the master branch. Would you mind taking a look and letting me know if it is clear enough?

Also, could you maybe post a link to the forum where people are asking questions? I check StackOverflow like once a month, but I am wondering where other people are asking questions so maybe I can jump on things like this sooner.

Edit: Thanks a lot for developing ttkthemes I really appreciate it. +1

Thank you! Positive feedback is what motivates me to work on a project more.

ghost commented 4 years ago

Yeah that looks good have you considered having it set to True by default? A user can set it to False manually if they don't want it.

RedFantom commented 4 years ago

@Azza-NZ I have actually considered it, but I want ThemedTk to be a drop-in replacement, changing behaviour only if the user actually requests it. I prefer opt-ins over opt-outs.

RedFantom commented 4 years ago

Version 2.4.0 is now available for use on PyPI, so I will be closing this issue. Thank you both for thinking with me about this!