【问题标题】:Create Custom Buttons in PySimpleGui在 PySimpleGui 中创建自定义按钮
【发布时间】:2022-01-21 17:31:59
【问题描述】:

我正在使用 PySimpleGui 制作一个 GUI,我希望我的一个按钮是一个圆圈,一个是更大的。有没有办法做到这一点?如果是这样,怎么做?我正在使用 TKinter 端口。

【问题讨论】:

    标签: python user-interface tkinter button pysimplegui


    【解决方案1】:

    尝试sg.Buttonimage_filenameimage_data 选项,并从主题设置中设置正确的按钮颜色,并将边框宽度设置为0。

    这是它的工作原理示例,请记住在以下代码中使用您的图像文件。

    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()
    

    【讨论】:

    • 你忘记了sg。我仍然收到错误“AttributeError:模块'PySimpleGUI'没有属性'image_filename'”
    • No sg 忘了这里,你可能会误解这里的东西。不要使用sg.image_filename 作为sg.Button 的选项,否则你会得到AttributeError: module 'PySimpleGUI' has no attribute 'image_filename'
    猜你喜欢
    • 1970-01-01
    • 2011-11-06
    • 2010-12-23
    • 2021-03-03
    • 2016-12-27
    • 1970-01-01
    • 2021-04-08
    • 2013-04-12
    • 2011-07-08
    相关资源
    最近更新 更多