Comments (4)
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.
self.update('Cancel', ('white',sg.theme_background_color()), False, red_hovered)
however fails otherwise. I'd be interested to know why & if there's a better way to do something like this.
from pysimplegui.
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
from pysimplegui.
Thanks, I thought I'd tried that but obviously not!
That works to the extent that I don't get an error & the correct graphic is displayed but I get the graphic button within a white box (per button_color parameter), which I'm trying to avoid. I tried updating that using the same syntax but it still left it within the white box, whereas if I don't name any parameters & just supply values up to the image source the white box is not displayed. I can live with that as a 'work around' but I am curious why it doesn't work as I would expect
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!
from pysimplegui.
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()
from pysimplegui.
Related Issues (20)
- [ Question] Is it possible for me to force update the values dictionary for my menubutton elements to None? HOT 10
- [ Enhancement/Question] Programmatically setting Horizontal Scroll position of a Column() HOT 9
- [Question] Demo_Matplotlib_Ping_Graph_Large.py does not run/compile on Pi4 HOT 26
- Flask click SystemError when used with pySimpleGUI output redirect HOT 1
- [Question] How to trap an event HOT 2
- [Enhancement] CI friendly handling for the first time installation dialog HOT 3
- [Question] How To Re-Enter Data For A Specific Field - AND 'CR to act like TAB HOT 1
- [ Bug] sg.ColorChooserButton Unless Additional Tkinter Import HOT 1
- [Bug] Hitting the image-count limit [Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize] HOT 6
- [Question] Import error HOT 3
- [Question] Change focus highlight when tabbing to button HOT 8
- [ Enhancement/Bug/Question] NOTE - you can also call sg.main() or sg.main_open_github_issue() to post an issue HOT 1
- [ Question] Compiling Errors since License validation HOT 2
- [ Bug] Broken Doc Link HOT 2
- [Question] NOTE - Table get doesn't work HOT 6
- [ Enhancement] allow arrowheads for lines in tkinter graphs HOT 8
- [Question] Question of shortcut HOT 17
- [Question] How to Use PySimpleGui Programs on Other PCs HOT 1
- [ Question] How to detect when we manually enter a value in combo box in Pysimple GUI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysimplegui.