-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to update class parameter within inherited class #6740
Comments
OK, I've sort of solved it. My hover method works if I include all parameters in order up to image source without using keywords eg. |
Firstly, I found that you use a string equal to a value in the method of update, it's wrong syntax. self.update('image_data'=red_hovered) >>> class Test():
... def update(self, image_data=None):
... print(image_data)
...
>>> test = Test()
>>> test.update("image_data"=1)
File "<stdin>", line 1
test.update("image_data"=1)
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="? It should be self.update(image_data=red_hovered) >>> test.update(image_data=1)
1 |
Thanks, I thought I'd tried that but obviously not! Interestingly, I create the button with button_ color = ('white', background). If I reverse them within the 'hover' method & then reverse them again, back to the original in my 'unhover' method it all displays correctly with no white box! |
Not sure what you mean, better with code and pictures to show what your expectation. Example code import PySimpleGUI as sg
bg = sg.theme_background_color()
data = [sg.EMOJI_BASE64_HAPPY_LAUGH, sg.EMOJI_BASE64_CRY]
color = [('white', bg), (bg, 'white')]
layout = [
[sg.Button("", image_data=data[0], key="1st", metadata=0, border_width=0, button_color=color[0]),
sg.Checkbox("Change Background", key="Bg")],
]
window = sg.Window("Title", layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == "1st":
element = window[event]
element.metadata = 1 - element.metadata
element.update(image_data=data[element.metadata], button_color=color[element.metadata] if values["Bg"] else None)
window.close() |
Type of Issue (Enhancement, Error, Bug, Question)
Question
Environment
Operating System
Linux version ('glibc', '2.35')
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Python version (
sg.sys.version
)3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
PySimpleGUI Version (
sg.__version__
)5.0.3
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)8.6.12
Your Experience In Months or Years (optional)
0 Years Python programming experience
30 Years Programming experience overall
Yes Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
This may be more a Python thing I'm missing but I have created a class, inherited from sg.Button. I set various parameters within the class (image_data, text etc.) & then want to update the image from within a method. My program code calls the method correctly
window['Cancel'].hover()
and if I use
window['Cancel'].update(image_data=red_hovered)
from within the program it works correctly, however I cannot get the method to compile when I try it within the class. I have tried self.update(image_data=...), super().update(...) and various similar options but I get a syntax error every time (expression cannot contain assignment).
What am I missing? Thanks
Code To Duplicate
Screenshot, Sketch, or Drawing
The text was updated successfully, but these errors were encountered: