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.
Related
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.
I found this answers on Stackoverflow but nothing works for me
How to hide console window in python?
Hiding the console window
Hide console window with Tkinter and cx_Freeze
I'm trying to hide console window, on windows at least. But with solutions above still I have window open
The only difference maybe I have to mark, I run python application with process from C# application, but as I understand it can't be a reason of some key different if I write all directives from the python code. Now I'm not sure how to figure out
You need to use the pythonw.exe program as it won't open a terminal when ran.
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!!!
I am a complete newbie at Python. Meanwhile, I'm working with Tkinter to integrate a GUI into my application using Python 2.7. This is the code so far:
import Tkinter
top = Tkinter.Tk()
top.mainloop()
However, when I execute the file, a console window and the GUI pops up. How do I get rid of the console window during startup?
Rename your Python script as .pyw (not .pyc). This will tell the invoker to to instantiate a console window. Source
Note however, this will work for non-GUI based scripts too which can cause undesireqable behaviour - such as not being able to see your script.
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