Is there any way to remove the click animation in Python Tkinter? - python

When I click a button in Tkinter, an effect shows up. Can I somehow remove it?
button
button when clicked
I tried to google the problem, but found nothing useful :(
Btw, sorry for the bad English, I hope it's not too disturbing.

You can disable the animation of a button by returning "break" in the widget's bind, which stops the propagation of bound functions.
So you can either alter the function you normally have bound to the button to return "break".
Or you can add another bind, this does however prevent any binds that are made after this one

You can use relief='sunken', however, the style of the button will always appear to be pressed.
btn = Button(frame, text='Btn', relief='sunken')

Related

Python Custom Tkinter. Hover effect on buttons when selected with Tabulator key

So I have used .bind() on all my buttons and basically I would like to see which button is currently 'selected' when I switch between them with tabulator key. I did spend already quite a while on search for solution but didn't found anything useful. I don't know how to grab that moment when after pressing Tab key focus is on a button.
When there is more widgets I can .bind() Tab key to a widget proceeding button to simply just change foreground of a button but this won't work in case when I have only buttons in frame because first button will be omitted and that's not a clean and right solution to my issue.
If I bind Tab key to that button and change foreground then it's changed but after pressing Tab when button was already selected.
I don't know is there any clean solution for that problem or I will have to for frames that have only buttons create some starting_dummy widget that would initiate change for a first button.
Haven't found a way to detect is Tab key focused at this moment on a particular button (like it is with hover and cursor) but I know when it's going to be so I used that and solved case with only buttons in frame. It's based on what I already wrote in the question - I'm binding Tab key with a function to a widget preceding button to change button colour while button is bind to a function that's changing colour back to normal like this:
self.entry.bind("<Tab>", self.focus_in)
self.button.bind('<Tab>', self.focus_out)
def focus_in(self, event):
self.button.configure(fg_color='white')
def focus_out(self, event):
self.button.configure(fg_color='black')
For the case when only widgets in the frame/root are buttons, like in a menu that I got first I focus_set() on the last button and make a functions that circulate colours on and off at on Tab like this:
self.button2.focus_set()
self.button1.bind('<Tab>', self.focus_in)
self.button2.bind('<Tab>', self.focus_out)
def focus_out(self, event):
self.button1.configure(fg_color='white')
self.button2.configure(fg_color='black')
def focus_in(self, event):
self.button1.configure(fg_color='black')
self.button2.configure(fg_color='white')
Whit a custom made buttons it's just matter of replacing fg_color with a image.
If you use a button as an image holder for your logo or so, then just set state='disabled' and it will be omitted.

How do I stop a disabled tkinter button from being greyed out?

Basically, I've got a tkinter button with an image on it, and when I disable the button it greys out a square around the image and looks pretty bad. Is there any way to stop this from happening while keeping the button disabled?
Instead of disabling the button, you can unbind the callback:
button['command']=0

How to close tkinter window without a button and not closing Python completely?

I am aware that there are commands such as .destroy() , .exit() etc. However, when taking these out of the 'command' from the button parameter of what action to take when pressed, they don't work.
My scenario is when a user logins successfully, the Tkinter window including its widgets should close whilst short after a GUI in pygame opens. I just don't want the Tkinter window to be there once I don't need it ever again whilst also not exiting Python. I don't want a button as I want the process to be automatic.
The thing that baffles me is why when taking out this command to be on its own, it does not work:
Button(root, text="Quit", command=root.destroy).pack() #works
root.destroy() #don't works
Without seeing more of the source code, I guess the problem is based on where you call root.destroy()
If it comes after the blocking tk.mainloop(), it will never be reached. Please read Tkinter understanding mainloop regarding this issue.
A possible solution based on the above:
while True:
tk.update_idletasks()
tk.update()
if login_successful: # or whatever your login check looks like
root.destroy()
You replace the mainloop with your custom loop, which includes a check for a successful login.

wxpython SearchCtrl two events triggered

I am using a SearchCtrl with a dropdown menu and I'm having some trouble with the events. When I click the little arrow next to the search button, the EVT_SEARCHCTRL_SEARCH_BTN is triggered, which is not what I want. I only want the EVT_MENU_RANGE to be triggered after I clicked an item, and not also the EVT_SEARCHCTRL_SEARCH_BTN before i click it.
self.search_ctrl = wx.SearchCtrl(self.panel_1, -1,
style=wx.TE_PROCESS_ENTER)
self.search_menu = wx.Menu()
self.search_items = {"text1":"value1", "text2":"value2"}
for txt in self.search_items:
self.search_menu.Append(-1, txt)
self.search_ctrl.SetMenu(self.search_menu)
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.search, self.search_ctrl)
self.Bind(wx.EVT_MENU_RANGE, self.onSearchMenu)
Although I should probably add id's to the menu bind, this isn't causing the problem. The code works as expected when I comment out the search button bind.
UPDATE
Apparently this isn't a problem, but a 'feature' of the searchctrl. I tried the wxpython demo and the menu also showed up if I just clicked the search button, and not the arrow. It is apparently one button, instead of the two i thought it was.
Is there a way to accomplish my original request? Do i have to manually modify a textctrl, or is there an other solution?
All the examples I've seen suggest you need to specify a range of IDs when you call your menu bind.
Maybe by default it binds to something unexpected... ?
Edit - In light of your update, it seems likely that you're going to need to make a custom control to me..

How do I disable a button after it's clicked in wxpython?

There are two buttons in my little program, start and stop. And what I want is to disable the start button after I click it, and when I hit the stop button it should return to normal. How can I do this? I googled for a while and couldn't find the answer, hope you guys can help me out.
Thanks!
Use the button's Enable and Disable methods in the appropriate event handlers. There's a sample available at the link below:
wxPython Button Demo
In this snippet we are playing around with wxPython's buttons, showing you how to bind the mouse click event, enable and disable, show and hide the buttons. Each button also has a tool-tip (hint) associated with itself.

Categories

Resources