Git Product home page Git Product logo

Comments (8)

TomSchimansky avatar TomSchimansky commented on May 16, 2024 1

It's a bug or a missing feature in customtkinter. So when you place a CTk element onto something I need to get the background color of the element on which the CTk element was placed. Then I can set the bg_colour of the CTk element to the bg color of the master, so that I can draw rounded corners. The rounded corners are just circles on a tkinter.Canvas which has the same bg color as the master on which the CTk element was placed so that you don't see the canvas and just the circles and rects on the canvas.

And at the moment I detect if the master widget as a tkinter widget, and if so, I read the bg color of the mastere by doing .cget("bg"). But that doesn't work on ttk widgets because they don't have a bg attribute, they have a style.

So I somehow need to get the style of the ttk element and from the style I can get the bg color, but I don't now if this will work. For now I will change the code so that it doesn't throw an error on ttk elements and just set the bg to black by default on ttk widgets . Then you have can set the bg_color attribute manually to the correct color if you want...

from customtkinter.

TomSchimansky avatar TomSchimansky commented on May 16, 2024 1

So the CTk widgets now work on ttk.Frame, ttk.LabelFrame and ttk.Notebook. But only with the default color:

Bildschirmfoto 2022-04-10 um 23 00 46
Program: test/test_ttk_frames.py

If the color gets changed by a ttk style, then you have to manually set the bg_color attribute of all CTk widgets on them to the new color, it's not possible to do this automatically for me at the moment.

But overall it would prefer to use a CTkFrame instead of a ttk.Labelframe because it's more convenient and you can also place a label at the top as I did in test/test_ttk_frames.py and add a border if you want.

from customtkinter.

demberto avatar demberto commented on May 16, 2024

Its a bug? Tkinter sure as hell has a lot of bugs to be called stable and mature

from customtkinter.

sumeshir26 avatar sumeshir26 commented on May 16, 2024

bg_color = tkinter.ttk.Style().lookup(".", "background")

from customtkinter.

TomSchimansky avatar TomSchimansky commented on May 16, 2024

I now, actually, what I do to get the bg color of the master widget is this on ttk widgets:

ttk_style = ttk.Style()
return ttk_style.lookup(self.master.winfo_class(), 'background')

customtkinter/widgets/customtkinter_button.py line 144

The problem is, that I cannot now if the style gets changed afterwards in the runtime of the program. Then I would have to change the bg_color of the ctk button again. On tkinter widgets, I do this by overwriting the configure method of the master, so that all the ctk childs on that master get notified when the bg color of the master gets configured. But with ttk i can't do this, because the bg change of the master doesn't happen through the configure method, but a style change. And there is nothing like a style change event or something similar.

from customtkinter.

demberto avatar demberto commented on May 16, 2024

And there is nothing like a style change event

There is <<ThemeChanged>>, although I am not sure you need it.

from customtkinter.

TomSchimansky avatar TomSchimansky commented on May 16, 2024

ThemeChanged only gets called if you load a new theme, but there is no event for individual theme modifications on widgets, so I will close this one.

from customtkinter.

demberto avatar demberto commented on May 16, 2024

@TomSchimansky There's also <Configure> maybe that's what you are looking for?

from customtkinter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.