Home > front end >  Create Custom Buttons in PySimpleGui
Create Custom Buttons in PySimpleGui

Time:12-22

I'm making a GUI with PySimpleGui and I want one of my buttons to be a circle and one to be bigger. Is there a way to do this? If so, how? I'm using the TKinter port.

CodePudding user response:

Try option image_filename or image_data of sg.Button, and set correct button color from theme setting, also set border width to 0.

Here's example how it work, remember to use your image file in following code.

import PySimpleGUI as sg

font = ('Helvetica', 12, 'bold italic')
sg.theme('Dark')
sg.set_options(font=font)
colors = (sg.theme_background_color(), sg.theme_background_color())

layout = [
    [sg.Button('Blue\nCircle', button_color=colors, image_filename='d:/circle_blue.png', border_width=0)]
]
window = sg.Window('Image Button', layout, finalize=True)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
window.close()

enter image description here

  • Related