Is it possible to set activeforeground/activebackground using customtkinter? - python

I am able to use activeforeground and activebackground to change color in background/text when button is clicked in tkinter.
Is it possible to do the same thing in customtkinter as well? I have checked the website if similar context is available, however, could not see any.
Thanks in advance.

From both the documentation and the GitHub webpage, I could not see any changes that would suggest this is possible.
You cannot have it on the button event function, so that the moment the button is clicked, the background and foreground is changed and then it is changed back to the normal. This is beacuse the the switch will be too fast and it does not work if you add sleep().
The closest work around that you can have is probably just to have it on the hover event as I belive the Hover event may be interfering with the changing of the colour in runtime straight away. If this is a deal breaker you may want to use PySide2/6 instead as they do have this exact custimastion readily availabe.
Also for anyone else interested in Custom Tkinter, make sure to use the GitHub page to see any progress or fucntions as it is mantained, the best documentation is from the Wiki found at:
https://github.com/TomSchimansky/CustomTkinter/wiki

Related

PySimpleGui - window size doesnt autofit dynamically

I'm trying to auto resize a PySimpleGUI window.
consider the following:
import PySimpleGUI as sg
CommandWindow = sg.Multiline(size=(80,20),echo_stdout_stderr=True,key=OUTPUT_KEY,visible=False)
window = sg.Window("FOO", layout=[CommandWindow],element_justification='center')
when the event is triggered, a sg.Multiline element's visible trait is updated to True.
then I refresh the window and it resizes (expands) to fit the element shown inside.
when I change the visible trait to False again, the window maintain its size and doesnt shrink back.
the execution as follows:
window[OUTPUT_KEY].update(visible=True/False)
window.refresh()
I think this will perhaps be the best answer I can come up with since StackOverflow answers do not age well, especially for the PySimpleGUI project which is ever-evolving.
The Demo Browser utility is made specifically to help answer questions like this. Of course, the documentation should also be used (PySimpleGUI.org).
The Demo Programs serve many purposes. One is to show specific techniques. The Demo Browser is a way for you to quickly and easily search, edit, and execute this code.
The attached screenshot is what I see when searching for "shrink" using this tool (as of Aug 2022...). The first item answers this specific issue. Maybe I got lucky? "I would rather be lucky than good". The docs and tools provided with PySimpleGUI are the best place to turn for questions rather than SO. They'll be the most accurate, the most up to date, and are part of the project itself.
Good lucky Jedi!
what solved it for me, Thanks to #Mike from PSG,
is using:
sg.Pin(,shrink=True)
as shown in docs: https://www.pysimplegui.org/en/latest/call%20reference/#layout-helper-funcs

Using Python, how to stop the screen from updating its content?

I searched the web and SO but did not find an aswer.
Using Python, I would like to know how (if possible) can I stop the screen from updating its changes to the user.
In other words, I would like to buid a function in Python that, when called, would freeze the whole screen, preventing the user from viewing its changes. And, when called again, would set back the screen to normal. Something like the Application.ScreenUpdating Property of Excel VBA, but applied directly to the whole screen.
Something like:
FreezeScreen(On)
FreenScreen(Off)
Is it possible?
Thanks for the help!!
If by "the screen" you're talking about the terminal then I highly recommend checking out the curses library. It comes with the standard version of Python. It gives control of many different aspects of the terminal window including the functionality you described.

Template matching results when the template is not on the original image

For testing purposes I'm building a bot that clicks on buttons in the screen. I have a folder with all the possible buttons that needs to be pressed and the application being tested only has one button shown at a time. There is no situations where two or more buttons appear together on the screen.
My approach is to take a screenshot every few seconds and loop through all the possible buttons and try to find them on the screenshot. If the button is found the bot clicks the center of the button.
My issue is that even if the button is not present on the screenshot the template algorithm I'm using returns a false positive somewhere in the screen. Is there any way to make sure no false positives are returned unless the button exists on the image?
I'm using python with numpy and skimage. For the template matching I'm using skimage.feature.match_template.
I already tried with opencv using SIFT and all those things with not much success and a lot of issues with opencv itself.
P.S.: If you think there is a better way to solve the problem itself (testing an app by pressing buttons) they are welcome too.
Cheers
Edit 1:
These are the images:
Edit 2:
The output of the script (false positive)
As I realised later on, the only way to make sure the detected image is indeed the one you are searching for is to compute the difference between the detected one and the template and use a threshold to allow for imperfections.

Swipe-Layout using PyGTK

I would like to implement a swipe or flipper view (widget) using PyGtk for my Quickly app. There should be a titlebar that contains the title of the currently showed content and the titles of the previous and next entry. To navigate threw the different entries you should be able to click the titles or swipe from left to right or vice versa.
But I do not know where to start.
Which Widget should I extend?
Would the Notebook widget the right choice?
How could I change the style of a Widget?
How do I implement the flip effect?
Do I have to combine different views (widgets) for the content pane and the titlebar?
For a better understanding of my problem view the screenshot below.
Thanks and best regards
Andreas
You might want to take a look at Clutter. Though I think, this kind of UI-Design could be very unintuitive on a desktop machine.

How do I scroll a wxPython wx.html.HtmlWindow back down to where it was when the user clicked a link?

I am using a wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll down a list of links in a window smaller than the list. When they click on a link, I need to repaint the web page, but I want to return the page position back to where they clicked it.
I've tried MouseEvent.GetLogicalPosition() on the event, but it wants a DC and the best I've been able to do is get the same information as GetPosition(), so I must not be feeding it the right one.
I also tried HtmlWindow.CalcScrolledPosition(), but apparently that isn't available in HtmlWindow because I get a NotImplementedError...
What I would like is a scroll position that can be derived from the MouseEvent, or the OnLinkClicked information.
I know about HtmlWindow.ScrollToAnchor(), but it's flaky and unaesthetic -- I would prefer to bypass it if possible so that I can scroll back exactly to where the user clicked.
Thanks!
how about having a look at the source of wxHtmlWindow for inspiration? for example at wxHtmlWindow::LoadPage(): it
// store[s the current] scroll position into history item:
int x, y;
GetViewStart(&x, &y);
(*m_History)[m_HistoryPos].SetPos(y);
this saved scroll position is used in wxHtmlWindow::HistoryBack():
Scroll(0, (*m_History)[m_HistoryPos].GetPos());
Refresh();
to go back to the saved position.
i would assume that this built-in "go-to-the-last-position-in-window" handling isn't the most "flaky and unaesthetic". could something similar work for you, too?
Maybe a bit late, but with some tips from ax, and some hints from here, I think that calling:
scrollpos = wx.html.HtmlWindow.GetViewStart()[1]
and storing that, and then later doing a call to:
wx.html.HtmlWindow.Scroll(0, scrollpos)
works for me. Of course, you do need to change wx.html.HtmlWindow to an actual reference to an instance.
Here is what I am doing to scroll page to previous position.
I do this to avoid blinking.
pos = self.GetViewStart()[1]
self.Freeze()
self.SetPage(src)
if save_scroll_pos:
self.Scroll(0, pos)
self.Thaw()
Usually, click events are trigged by MouseUp events. If you track the mouse position by capturing any MouseDown events, you will know where the last click (MouseUp) happened, and that should allow you to reconstruct things.
For this particular problem, you might have to do a bit more work in MouseDown like checking if they are within the wxHtmlWindow control and if so, then saving something like a line number.

Categories