When trying to close my tkinter window using the red 'x' button (top left) the window doesn't close and python crashes(colour wheel).
(note this is across all of my Tkinter apps, not just the one shown)
Here is an image of my code:
Here is the crashed white box, neither "quit" or red "x" works. It doesn't show up in the screenshot but the spinning colour wheel is visible whenever I hover over my window. I have to force quit due to "Python not responding".
Got me thinking when I run python in the shell there's an error message: TK Tcl. Maybe unstable.
I suggest to try master.destroy instead of frame.quit for the callback of the Quit button, and give us feedback whether it changes anything
Related
I am using a code designed by another person in MAC OS. I am using Windows instead and have slightly modified it, but the problem comes when using the GUI that is created.
I have already dealt with a similar issue with a slider. Once I pressed the slider, I couldn´t release it or press another button. I was forced to quit the GUI and start again. I solved it by changing the event command from EVT_COMMAND_SCROLL to EVT_COMMAND_SCROLL_THUMBTRACK. However I did not understand why it worked in MAC OS and does not work in Windows.
Now, I want to close the GUI with the typical cross inside the red button in the right corner of the window. I can do it if it is the first order I do in the GUI. If I first press any button or slider, the exit button does not work.
It made me consider if a major problem is hidden in the code which I am not seeing. I am new at wxPython, which is the module used in the code.
I just ask for your opinion and hope it is a basic error.
Thanks very much
I've been having problems running my python program on the mac.
Opening without the IDLE:
Firstly, whenever I open the program it opens with the IDLE by default. I would like it to open with the launcher, but when I tried opening it with the launcher, it came up with a preferences window that had no "Ok", "Next", or "Continue" button.
On Windows, if you open a python program, then by default it will run it with the launcher, causing it to go directly into the program without the user needing to go through any other windows. The .pyw extension can also be used to make it run without the console. How would I set the Mac so that it does this?
Background of tkinter buttons:
In the following function I have a menu with several buttons:
def MainMenu():
Move() # This clears any widgets that are on the screen.
Win.unbind("<Up>") # Win is the name of my window.
Win.unbind("<Down>")
Win.unbind("<Return>")
Win.config(bg="#FFFF00")
try:Welcome=GUI.Label(Win,text="Welcome "+Name+("."if Name[-1]!="."else"")+"\nYou should have £"+str(Cash)+("0"if str(Cash)[-2]=="."else"")+".\n What would you like to do?",bg="#FFFF00") # GUI is the variable containing the tkinter library.
except IndexError:Welcome=GUI.Label(Win,text="Welcome "+Name+".\nYou should have £"+str(Cash)+".\n What would you like to do?",bg="#FFFF00")
Welcome.place(x=0,y=0)
ManualButton=GUI.Button(Win,text="Manual adjustment.",width=96,height=4,command=ManualChange,bg="#FFFF00")
ManualButton.place(x=0,y=0)
RecButton=GUI.Button(Win,text="Recall.",width=96,height=4,command=Recall,bg="#00FF00")
RecButton.place(x=0,y=0)
Setti=GUI.Button(Win,text="Settings",command=Settings,bg="#FFFF00",width=96,height=4)
Setti.place(x=4,y=4)
if Set:
RecoButton=GUI.Button(Win,text="Record spending.",width=96,height=4,command=Spending,bg="#FF80C0")
RecoButton.place(x=256,y=14)
Win.update_idletasks()
Welcome.place(x=Win.winfo_width()//2-Welcome.winfo_width()//2,y=16)
ManualButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=256)
RecButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=192)
if Set:RecoButton.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=128)
Setti.place(x=Win.winfo_width()//2-ManualButton.winfo_width()//2,y=340)
Win.update()
Here is a picture of the menu it creates (Name="S", Cost=8805.33, Set=True):
This is what it looks like on a Mac (Name="S", Cost=96, Set=True):
I would like to make the buttons look more like they do on Windows, or at least get rid of the grey space around the buttons. Does anyone have any idea how I'd do this?
Is it possible to capture a screenshot of a wxpython GUI program when the program menu on the menu bar drops down?. I attempted to do this by pressing the print screen key on my keyboard but it didn't work.
Nevertheless, the print screen function key works fine when the menu on the menubar does NOT drop down.
I noticed I can take screenshots of other GUI programs on my system when their menu options are seen .
If this is possible, what codes can I place in my program to facilitate a successful screenshot when any menu is showing?
I just tried "Shift-prt scr" on my Windows 8.1 to capture a screen with a menu shown (used the wxPython demo) and it worked for me.
You can also use a screen capture utility, e.g. I often use IrfanView, to do this, with it I set a timer to capture things which go away when the window looses focus.
With Ubuntu using Mate under Applications--> Accessories there is a Take Screen shot option.
The actual command is mate-screenshot --interactive
this allows you Full screen, Current window or Selected area, with a "Grab delay", I found it particularly useful documenting wxpython, although you will have to drag the window to a size to accommodate the full menu or you end up with it cut off.
Note: gnome-screenshot --interactive, is another alternative.
Edit:
Have you checked out pyscreenshot?
https://pypi.python.org/pypi/pyscreenshot
It claims the following usage:
Example:
import pyscreenshot as ImageGrab
# fullscreen
im=ImageGrab.grab()
im.show()
# part of the screen
im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
im.show()
I'm using Python 2.7.4 with Gtk3 on Ubuntu 13.10.
I'm using the Keybinder library to hide and show my Gtk window using a hotkey. Now, when my window does show up using the hotkey, it does not always receive focus.
The concerned code is below:
def toggle(self, key, data):
if self.hidden:
self.hidden = False
self.set_keep_above(True)
self.set_accept_focus(True)
self.present()
self.enteredName.grab_focus()
else:
self.hidden = True
self.hide()
Here, self refers to the Gtk window and self.enteredName is a widget of type Gtk.Entry().
Normally, the combination of set_accept_focus(), set_keep_above(), followed by present() works. Without the set_keep_above, my window doesn't rise to the top. Without the set_accept_focus, my window doesn't get keyboard focus.
The above set up works when I just start my app and then test it using the hotkey (hiding and showing it). My window always receives keyboard focus. Howver, let's say I have a GVim window opened and I've given keyboard focus to it. On pressing the hotkey, my window shows up on the top (even on top of the GVim window), but the keyboard focus still lies with the GVim window.
I've tried several combinations (by adding activate), and grabbing focus on a text widget. But it's not working as expected.
Anything I'm missing here?
I'm trying to keep a Toplevel window from being closed in OSX by intercepting window manager WM_DELETE_WINDOW event.
#!/usr/bin/env python
from Tkinter import *
def speak():
print "woof"
root = Tk()
root.title("root")
win = Toplevel()
win.title("win")
win.protocol('WM_DELETE_WINDOW', speak)
root.mainloop()
When I run this I get two pop up windows titled "root" and "win". If I click on the red "x" close button on "win" to close the window, prints "woof" and then closes. However, if I run this same code on windows "win" stays open and keeps printing "woof" every time I click the red "x" close button.
How can I keep the Toplevel window from closing on OSX when I click the red "x" close button?
See the reply to Python Issue 12584. It appears to be a bug in the very buggy Cocoa Tcl/Tk 8.5 that Apple shipped with OS X 10.6. Don't use it or the Apple-supplied Pythons in 10.6 if you are using Tkinter or anything that uses Tkinter, like IDLE. More info here.