1

at this code im trying to use image as button but its being created next to button

import customtkinter
from PIL import Image

customtkinter.set_appearance_mode("System")  # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue")  # Themes: "blue" (standard), "green", "dark-blue"


img = customtkinter.CTkImage(dark_image=Image.open(r"C:\Users\user\PycharmProjects\Customtkinter\images\img.png"))



class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.grid_columnconfigure(1, weight=1)          # creating grid
        self.grid_columnconfigure((2, 3), weight=0)
        self.grid_rowconfigure((0, 1, 2), weight=1)

        self.title("Main Screen")                       # creating main screen
        self.geometry(f"{1100}x{580}")

        self.button = customtkinter.CTkButton(master=self, image=img)     #button (problem with img)
        self.button.place(relx=0.5, rely=0.5)


if __name__ == "__main__":
    app = App()
    app.mainloop()

i were trying to import button from figma using tk designer, but buttons had another colours, and text was moved. Also if it possible how to create gradient buttons using customtkinter?

1 Answers1

0

Add text = "" at the line you set the image for the button.

self.button = customtkinter.CTkButton(master=self, image=img, text="")
VanN
  • 27
  • 1
  • 6