I press this tkinter button, and the function bound to it finishes, but the button is stuck down. The rest of the gui is fine, its responsive, everything normal except for the button that is stuck down. I can even press the "stuck down" button again, and the bound function executes and finishes, but the button is still stuck down.
Sometimes the first few times I click the button it works fine and the button comes back up, but then after a few more clicks it will be stuck down. What could be causing this?
Here is the code for the button:
bf1=Button(self.canvas,text='F1',fg='tan1')
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
bf1.bind('<Button-1>',self.f1)
I have found what is causing this, it is the fact that I am using the 'bind' function instead of the 'command'.
When I use this, the button sticks if you move the mouse off the button before the callback finishes (you can only realistically do this if you have a lot of work to do in the callback):
bf1=Button(self.canvas,text='F1',fg='tan1')
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
bf1.bind('<Button-1>',self.f1)
But if you use the 'command', then there is no problem:
bf1=Button(self.canvas,text='F1',fg='tan1',command=self.f1)
bf1.grid(row=4,column=1,sticky='nwse',columnspan=4)
Is this a bug with tkinter's 'bind'?
Related
I have simple program with only one function which process files and then converts to pdf on a press of button. initially GUI window freezes while the function was running, after this I introduced threading into the program and now GUI freezing issue was resolved, but now when press the button again it shows below error
if anyone can help me on how to fix this and also explain how it works, that will be really helpful, as I am new to python and just started using Tkinter.
sample code would be even more helpful.
You shouldn't use the old thread object you used on the first button click. Instantiate a new one instead.
This is because, you can't start the same thread twice.
So maybe keep a list of threads and add a new one with each button click.
I'm just trying to simulate a mouse click every second but once the first click starts, the program just completely halts and I have no idea why
The program will continue if I press CTRL+C but then it halts again after it clicks:
import pyautogui
import time
while True:
time.sleep(1)
print("Clicking")
pyautogui.click()
And it doesn't matter which mouse library I use to simulate the click, it always halts. It should be clicking every second without interruption. What's wrong?
The only reason i think it does so is because it clicks at some place where it is not supposed to(by default the position is your current mouse pointer), so the pyautogui.click() takes 2 parameters x,y try specifying the the exact coordinate and it should work. To find the coordinates of a position place your mouse pointer there and run pyautogui.position().
I have a simple copy paste event, which should trigger a function while my program runs:
root = tkinter.Tk()
root.bind('<Control-c>', parse_item)
root.mainloop()
parse_item grabs the contents of the clipboard and makes some calculations.
The problem I have is:
It only works if my program is in focus. I need to be with the mouse in the program, then the bind event will trigger.
What I need:
The bind event should also trigger if the program is not in focus (for example the program is minimized). It should always trigger while the program runs.
It only works if my program is in focus. I need to be with the mouse in the program, then the bind event will trigger.
You cannot do that with tkinter. It can only operate on events in widgets that it controls, and only when it has focus. You would have to use a platform-specific tool to intercept events from other programs.
I have a Python 3.6.3 script that incorporates PyQt5. The GUI has a button that toggles play and pause of a video file. Pressing the spacebar also toggles play and pause. The button works fine all the time. The spacebar also works as intended, except at the very start of executing the script. I need to click some other event first (such as a button or slider bar) before the spacebar will correctly triggers the signal to pause or play the video. I want to start playing the video with the spacebar when the script starts up. Here is how I create the connections in the same __init__(self) function . As you can see, clicking on the button and pressing the spacebar both connect the signal to the same function (self.pauseVideo).
self.btnPause = QtWidgets.QPushButton(self.centralwidget)
self.btnPause.clicked.connect(self.pauseVideo)
self.spacebar = QShortcut(QKeySequence(Qt.Key_Space), self)
self.spacebar.activated.connect(self.pauseVideo)
Suggestions on how to get the spacebar to trigger the signal when the script first starts?
After a lot more searching, reassigning keyboard shortcuts (without success), etc., I found this post PyQt widget keyboard focus. I inserted
self.setFocusPolicy(Qt.StrongFocus)
into __init__(self) and it seemed to solve my problem! Now I'm just hoping it doesn't cause other issues.
I am showing a user a popup menu when they right click.
According to the popup behaviour, I want to destroy the popup when it looses focus(when user clicks outside the popup window). For that I tried to connect the popup window to "focus-out-event", using Glade. But for some reason, that event is not getting fired. I tried to print something on the terminal when the event is fired, but nothing gets printed.
I am new to Python and GTK, and now I have no clue how to proceed further.
#handler to catch the focus out event
def on_popup_menu_add_attachment_focus_out_event(self, *args):
print("Destroying the popup.....")
focus-out-signal and its handler
I just changed the Type as Top Level and it worked!