Rounded button tkinter python

前端 未结 4 960
无人共我
无人共我 2021-02-13 03:23

I am trying to get rounded buttons for my script using tkinter.

I found the following code:

from tkinter import *
import tkinter as tk

class CustomButto         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 04:01

    A very easy way to make a rounded button in tkinter is to use an image.

    First create an image of what you want you button to look like save it as a .png and remove the outside background so it is rounded like the one below:

    Click here to see image

    Next insert the image in a button with PhotoImage like this:

    self.loadimage = tk.PhotoImage(file="rounded_button.png")
    self.roundedbutton = tk.Button(self, image=self.loadimage)
    self.roundedbutton["bg"] = "white"
    self.roundedbutton["border"] = "0"
    self.roundedbutton.pack(side="top")
    

    Ensure to use border="0" and the button border will be removed.

    I added the self.roundedborder["bg"] = "white" so that the the background the background of the button is the same as the Tkinter window.

    The great part is that you can use any shape you like not just the normal button shapes.

提交回复
热议问题