-2

I am writing a program. I created the whole gui and its time to update my window according to events. Everything is pretty good but i think the PySimpleGUI developer actually missed button mouseover color to update. Usually it should be

window[key].update[mouseover_color=(bg_color, txt_color)]

Is there any method to do this?

Edit: I forget my one issue that since i can't add buttons to title bar i removed it and create my own title bar using multi-windows and bind it with other window.But the problem here is that without round corners the title looks very sick.

Please tell me a way to do this.

One more issue is that suppose the user clicked the button and new windows open over previous one but when i hover my mouse out of new window screen it disappear i mean it goes behind my main window even i set new window to keep on top = True

1 Answers1

1

Need tkinter code here to update the colors when mouse hover.

Different tkinter widget used as the button with different option use_ttk_buttons

  • With option use_ttk_buttons=False, it will use tkinter Button as sg.Button and it can update options activeforeground and activebackground by method configure of element.Widget
  • With option use_ttk_buttons=True, it will use tkinter.ttk Button as sg.Button and it can update related options by using tkinter.ttk Style.

Here's the demo code

import PySimpleGUI as sg


def update(element, colors):
    widget = element.Widget
    if isinstance(widget, sg.tk.Button):
        widget.config(activeforeground=colors[0], activebackground=colors[1])
    else:
        style_name = widget.configure()["style"][-1]
        style = sg.ttk.Style()
        style.map(style_name, foreground=[('active', colors[0])], background=[('active', colors[1])])

index = 0
color = {0: ("white", "blue"), 1: ("yellow", "green")}

font = ("Courier New", 16)
sg.theme("DarkBlue3")
sg.set_options(font=font)

layout = [[sg.Button("Hello", mouseover_colors=color[index], use_ttk_buttons=True)]]
window = sg.Window("test", layout, finalize=True)

while True:
    event, values = window.read()
    if event in (sg.WINDOW_CLOSED, 'Exit'):
        break
    elif event == 'Hello':
        index = 1 - index
        update(window['Hello'], color[index])

window.close()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23