Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing border in slider widget #21

Closed
IshanJ25 opened this issue Dec 23, 2021 · 16 comments
Closed

Removing border in slider widget #21

IshanJ25 opened this issue Dec 23, 2021 · 16 comments
Labels
question Further information is requested

Comments

@IshanJ25
Copy link

IshanJ25 commented Dec 23, 2021

image

I am unable to remove this border.
I edited some code to get .configure method for slider widget, and when I call this method, this thick border forms around the slider widget. How to remove this?

@TomSchimansky
Copy link
Owner

So you want to remove the white border around the slider? When you create the Slider with no arguments at all there is no border because the border_color argument is None by default and so the border_color is the color of the frame behind the slider. And when the slider gets a white border when you call your configure method, then you set the border_color to white in your configure method. But I can't do anything without seeing your code.

@TomSchimansky TomSchimansky added the question Further information is requested label Dec 23, 2021
@IshanJ25
Copy link
Author

IshanJ25 commented Dec 24, 2021

here is the code:

color = {'main': '#FFFFFF',
         'accent': '#F0F0F0',
         'text': '#141414',

         'red': '#FF3232',
         'red_': '#DC1414',
         'yellow': '#FFDC32',
         'yellow_': '#F0C800',

         'green': '#50C850',
         'green_': '#32B432',
         'teal': '#50C8C8',
         'teal_': '#329696',

         'blue': '#3296FF',
         'blue_': '#1478FF',
         'purple': '#9696FF',
         'purple_': '#1478FF',

         'white': '#FFFFFF',
         'white_': '#F0F0F0',
         'black': '#141414',
         'black_': '#323232',
         }

red_slider = ctk.CTkSlider(
    from_=0, to=len(slider_vals) - 1,
    command=red_slider_func,
    progress_color=color['red'],
    fg_color=color['accent'],
    button_color=color['white_'],
    button_hover_color=color['white_'],
    master=frame,
    height=slider_h,
    width=slider_w)
red_slider.place(x=gap_x, y=gap_y)
red_slider.configure(fg_color=color['accent'], bg_color=None)

    def config(self, *args, **kwargs):
        self.configure(*args, **kwargs)

    def configure(self, *args, **kwargs):
        require_redraw = False  # some attribute changes require a call of self.draw() at the end

        if "fg_color" in kwargs:
            self.fg_color = kwargs["fg_color"]
            require_redraw = True
            del kwargs["fg_color"]

        if "bg_color" in kwargs:
            if kwargs["bg_color"] is None:
                self.bg_color = self.detect_color_of_master()
            else:
                self.bg_color = kwargs["bg_color"]
            require_redraw = True
            del kwargs["bg_color"]

        if "progress_color" in kwargs:
            self.progress_color = kwargs["progress_color"]
            require_redraw = True
            del kwargs["progress_color"]

        if "button_color" in kwargs:
            self.button_color = kwargs["button_color"]
            require_redraw = True
            del kwargs["button_color"]

        if "button_hover_color" in kwargs:
            self.button_hover_color = kwargs["button_hover_color"]
            require_redraw = True
            del kwargs["button_hover_color"]

        if "border_color" in kwargs:
            self.border_color = kwargs["border_color"]
            require_redraw = True
            del kwargs["border_color"]

        if "border_width" in kwargs:
            self.border_width = kwargs["border_width"]
            require_redraw = True
            del kwargs["border_width"]

        if "from_" in kwargs:
            self.from_ = kwargs["from_"]
            require_redraw = True
            del kwargs["from_"]

        if "to" in kwargs:
            self.to = kwargs["to"]
            require_redraw = True
            del kwargs["to"]

        if "number_of_steps" in kwargs:
            self.number_of_steps = kwargs["number_of_steps"]
            require_redraw = True
            del kwargs["number_of_steps"]

        if "command" in kwargs:
            self.callback_function = kwargs["command"]
            require_redraw = True
            del kwargs["command"]

        super().configure(*args, **kwargs)

        if require_redraw:
            self.draw()

@IshanJ25
Copy link
Author

Any update?

@TomSchimansky
Copy link
Owner

I have no idea why youre getting a white border, just use the Slider as it is currently on Github, then there shouldn't be a change of the border color, it has a config function now.

@IshanJ25
Copy link
Author

still same. no change

@TomSchimansky
Copy link
Owner

If you still have problems you can .zip your whole project and add it to your comment, so I can run it myself, otherwise I will close this issue because its not reproducible for me.

@IshanJ25
Copy link
Author

IshanJ25 commented Jan 3, 2022

here is the repo
https://github.com/IshanJ25/my_color_picker

@TomSchimansky
Copy link
Owner

Hey, now I know what's the problem, its a missing feature in the library that is needed for changing the background object (frame) of any CTk object manually. I will add this in the next days. For a quick fix you could also set the border color, what is currently the white border, to your frame color (border_color=color['main']). But with the fix it should just work without this.

@IshanJ25
Copy link
Author

I have tried this: border_color=color['main'], No effect, still same

@TomSchimansky
Copy link
Owner

Just download the current repository, it should work.

@IshanJ25
Copy link
Author

do you suggest that I edit the latest version by adding these lines?

    def config(self, *args, **kwargs):
        self.configure(*args, **kwargs)

    def configure(self, *args, **kwargs):
        require_redraw = False  # some attribute changes require a call of self.draw() at the end

        if "fg_color" in kwargs:
            self.fg_color = kwargs["fg_color"]
            require_redraw = True
            del kwargs["fg_color"]

        if "bg_color" in kwargs:
            if kwargs["bg_color"] is None:
                self.bg_color = self.detect_color_of_master()
            else:
                self.bg_color = kwargs["bg_color"]
            require_redraw = True
            del kwargs["bg_color"]

        if "progress_color" in kwargs:
            self.progress_color = kwargs["progress_color"]
            require_redraw = True
            del kwargs["progress_color"]

        if "button_color" in kwargs:
            self.button_color = kwargs["button_color"]
            require_redraw = True
            del kwargs["button_color"]

        if "button_hover_color" in kwargs:
            self.button_hover_color = kwargs["button_hover_color"]
            require_redraw = True
            del kwargs["button_hover_color"]

        if "border_color" in kwargs:
            self.border_color = kwargs["border_color"]
            require_redraw = True
            del kwargs["border_color"]

        if "border_width" in kwargs:
            self.border_width = kwargs["border_width"]
            require_redraw = True
            del kwargs["border_width"]

        if "from_" in kwargs:
            self.from_ = kwargs["from_"]
            require_redraw = True
            del kwargs["from_"]

        if "to" in kwargs:
            self.to = kwargs["to"]
            require_redraw = True
            del kwargs["to"]

        if "number_of_steps" in kwargs:
            self.number_of_steps = kwargs["number_of_steps"]
            require_redraw = True
            del kwargs["number_of_steps"]

        if "command" in kwargs:
            self.callback_function = kwargs["command"]
            require_redraw = True
            del kwargs["command"]

        super().configure(*args, **kwargs)

        if require_redraw:
            self.draw()

@TomSchimansky
Copy link
Owner

You don't need to edit anything the problem that the border color remains the same as it was initially (white) is fixed in the current Github version.

@TomSchimansky
Copy link
Owner

Just as a tip you could use a CTkLabel and a CTkEntry for the objects marked in red. Then the text would be centered and the entry would look clean. Otherwise the program looks really good!

Bildschirmfoto 2022-01-16 um 00 23 34

@IshanJ25
Copy link
Author

IshanJ25 commented Jan 16, 2022

Thanks
I just used classic tkinter entry on CTK frame because as you mentioned here: #17 (comment) the text variable parameter is not available yet. I will surely implement CTK entry and label once they get text variable implementation

EDIT: a question
Is there a way to force-antialiasing in windows? the one on mac looks way better than on windows

@TomSchimansky
Copy link
Owner

Ahh okay, tkinter variables are actually there for all widgets since today in the Github version.

And because of the antialiasing on windows I already did a lot of research and it seems like its not possible with the normal tkinter canvas. A solution would be to use this (https://web.archive.org/web/20200619012602id_/http://effbot.org/zone/pythondoc-aggdraw.htm) for drawing, which is compatible with tkinter, but it looks like you cannot reference specific objects on the canvas, just draw on top or clear the whole canvas. Maybe I will try to render the widgets with this library on Windows...

@IshanJ25
Copy link
Author

okay thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants