pygtk crash in windows XP - python

I'm trying to run this quite simple example with gtk in windows XP (32 bits):
import pygtk
import gtk
def create_window():
window = gtk.Window()
window.set_default_size(200, 200)
window.connect('destroy', gtk.main_quit)
label = gtk.Label('Hello World')
window.add(label)
label.show()
window.show()
create_window()
gtk.main()
The program shows the window, but just after that (I think that when it reaches "gtk.main()") it crashes showing the message "python.exe has encountered a problem and needs to close".
Somebody has a possible solution?
SOLVED: You can have python (or the whole Anaconda package) installed, but you HAVE to eliminate whatever pycairo, gtk or pygtk module which is alredy in your computer. When you are sure of that, just run the file pygtk-all-in-one adequate for you (http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/), and, if you are lucky... It is done!!!

As per OP's update in the question:
SOLVED: You can have python (or the whole Anaconda package) installed,
but you HAVE to eliminate whatever pycairo, gtk or pygtk module which
is alredy in your computer. When you are sure of that, just run the
file pygtk-all-in-one adequate for you
(http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/), and, if
you are lucky... It is done!!!

Related

Python 3.8.9 MacOS M1 tkinter UI not opening inside of VSCode

so I am trying to use Tkinter inside of VSCode on my M1 mac. When I use Tkinter through IDLE it works fine but once I try to open it inside of VSCode it the UI submenu just stalls. I'm using python 3.8.9 as my kernel but it won't seem to open even when I switch to any other versions. Tkinter is installed fine it is just some issue with how VSCode is running it but I have no idea how to fix it.
import tkinter as tk
window = tk.Tk()
Here I provided some screenshots of what happens
While using Idle
While using VSCode (The app just bounces up and down never opening the UI)
You have not started the event loop. IDLE does mainloop for you, otherwise, you need to call it by yourself.
import tkinter as tk
root = tk.Tk()
root.mainloop()
You can refer to here.

TKinter (filedialog.askdirectory) freezing Spyder console

I noticed in other questions that there are (or were) several problems with TKinter in Spyder. I have been using it in IDLE for a while but I am moving to Spyder, and came upon some problems.
I am running Python 3.6.4 with Spyder 3.2.8 from Anaconda 1.8.4, on Windows 7 Enterprise.
When I try to use some TKinter functions (like filedialog.askdirectory) Spyder´s console freeze.
I´ve been reading different forums but still no one has the same problem or a solution to this problem.
Here is a simple code that would work in IDLE, but not in SPYDER:
import os
from tkinter import Tk, filedialog
Tk().withdraw()
print("Done WITHDRAW")
currentdir= os.getcwd()
print("Done GETCWD")
filename= filedialog.askdirectory(title="Select folder", initialdir=currentdir)
print("Done ASKDIRECTORY")
As a result, I get:
runfile('M:/Users/KPK2/.../hello.py', wdir='M:/Users/KPK2/...')
Done WITHDRAW
Done GETCWD
And the console keeps running, waiting for the ASKDIRECTORY to pop a new window to select a file. In IDLE it works just fine.
Does anyone know which could be the problem and some possible solution?
I read on other threads solutions like updating to Spyder 3.0 (I already have 3.2.8) or changing some "External Modules" for the "Console" in Preferences, but there is not such a tab on my Prefereneces window (don´t know how to do that otherwise).
Thank you.
try running this command %gui tk at the console before running your code.
The alternative is it go to Tools > Preferences > IPython Console > Graphics > Graphics backend and select tkinter there.
This worked for me :)
The answer was found here https://groups.google.com/forum/#!topic/spyderlib/rFJhJZgjZTE

Running wxpython app in cygwin/X

I have installed and tried both wxpython-3.0 and wxpython-2.8 for python2.7 from the standard cygwin repos (64-bit, Win 7). However when I start the Cygwin X server and try to run the most simple "Hello World" script from wxPython tutorials:
# test.py
import wx
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
frame.Show(True) # Show the frame.
app.MainLoop()
I get a Gtk-WARNING **: Screen for GtkWindow not set which eventually ends in a segmentation fault.
The DISPLAY variable is set to :0 (export DISPLAY=:0) and corresponds to the started X server.
Is wxPython broken in cygwin or is some other procedure necessary prior to launching a script using wxPython?
I tested this and got it working for my cygwin64 installation. I used
python v2.7.14 and
cygwin package python-2-wx version 3.0.2.0-3
Both installed via the cygwin installer.
I also have the python-2-wx2.8 in my cygwin install, and I can select which one is to be used by creating the file /usr/lib/python2.7/site-packages/wx.pth containing only one line specifying the relative path to the package to be imported by the "import wx" line:
wx-3.0-gtk3
or
wx-2.8-gtk2-unicode
When I use the later (wx-2.8-gtk2-unicode) I get the same error as you mention, "assertion 'GDK_IS_DISPLAY (display)' failed", but when I use wx-3.0-gtk3 the errors disappear and the script runs fine and I can see the graphics in my X-window.
Try starting your X server with the startxwin command instead of xinit.
startxwin &
export DISPLAY=:0.0
./test.py
I was able to get your test code running with this sequence.

Hiding the console window

problem
I started designing GUI applications using Python and Tkinter. When I freeze a script using cxFreeze then when I run that EXE file on a machine. Then first the console window (a black DOS shell in the case of Windows XP) opens and then the main window(Tk() instance) gets initialized.
goal
The console window must not appear. Only the Tk() instance should appear.
code
root = Tk()
Label(root,text="hey").pack()
root.mainloop()
specs
Windows XP SP 3
Python 2.7
Tkinter 8.5
When using py2exe use windows=['main.py'] instead of console=['main.py'] when creating your setup.py
For cx_Freeze this answer might help you: https://stackoverflow.com/a/11374527/2256700
I'm not sure if this is the answer anyone is looking for, but renaming the file extension from .py to .pyw under Python 3.4 and Win32 will effectively suppress the Python shell. You'll just get your Tk GUI window.
Say your python script is called "myscript.py".
Create a file called runme.vbs containing code:
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("myscript.py", 0, True)
Set WshShell = Nothing

PyGTK Window Crashes When Created

I am trying to create a simple PyGTK window running on Windows 7. I used the PyGTK-all-in-one installer from: ftp.gnome.org to install the necessary PyGTK dependencies for 32-Bit Python 2.7.2. However, whenever I create a simple GTK window in IDLE using the code:
import gtk
mainWindow = gtk.Window()
mainWindow.show()
the window is displayed, but instantly stops responding and is unable to be moved, re-sized, etc. Is there a simple way to prevent this from happening?
Thank you in advance!
Running my code from the PyGtk Command Prompt rather than IDLE prevents the window from crashing.
Edit: Adding a main loop to my code, as noted here, prevents the window from crashing when run with IDLE.

Categories

Resources