I'm making a simple game using the Pygame Module. I require a Tkinter window to be open alongside the Pygame window.
Whenever I try to open both the windows, the second window only opens after I kill the first one.
Now, the only solution I can think of, is using multi-threading. But, I'm not able to implement it.
How do I go about this?
I would really appreciate some help here.
Thank You!
There is a fundamental design issue in pygame that makes it unable to open a window if the process already has a window. It will also prevent other windows from opening while it is running. However, you can open as many TK windows as you like and you can embed a pygame window inside a SDL drawing frame inside a TK window.
See this answer on how to use the drawing frame: Embedding a Pygame window into a Tkinter or WxPython frame
See this answer on how to create multiple windows in tkinter: How to open multiple windows in Tkinter
Related
I am using
import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 6 )
to close the console and leave the pygame window open however I have to click on the window to interact with it. Can I make it so it goes back to the pygame window automatically?
A python script may be run in windowed mode by launching with pythonw, this may be automatically handled by changing the file extension to .pyw.
See this answer for more detailed information.
I am trying my first steps in tkinter. I use Spyder as IDE in Python 3.5.1 |Anaconda 4.0.0.
I want to run the very simple script below but it always crashes my Spyder. In a normal shell/bash it runs though and opens the canvas.
import tkinter as tkr
tk = tkr.Tk()
canvas = tkr.Canvas(tk, width=500, height=500)
canvas.grid()
tk.mainloop()
Under Preferences for the Ipython Console I already tried different settings (i.e. Qt, Automatik, Tkinter) but none of it did help.
What am I doing wrong (and how can I do it better)?
many thanks in advance
update to Spyder 3.0.1
https://pythonhosted.org/spyder/
https://github.com/spyder-ide/spyder/releases/tag/v3.0.1
I just did this on win 10: no crash, got blank "tk" separate window
You should try to change the graphics backend
Go to tools/preferences/I-python Console/Graphics and in backend change it to Tkinter.
That should do it!!
In the Spider menu bar, go to: Tools > Preferences
A window will open, then on left side go to: Completion and linting
In the right side, go to: introspection and below you will see different modules available in your current spider
In the section "Preload the following modules...", add tkinter to the end of the list
I found this suggestion while trying to get tkinter to display a GIF image in a label. First, on a Mac, the Tools menu item does not contain Preferences--look under the "python" menu instead. Even so, I have the
IPython Console Graphics backend set to Tkinter and tkinter is added to Completion and Linting. But all I get when launching from Spyder is an empty frame entitled "tk #442", whereas when I launch from the command line I get a frame with a nice GIF image as expected.
I'm quite new to linux, raspberry, tkinter and python and therefore I need some guidance to get on the right track.
I'm running Arch Linux on a raspberry pi and I want a quite fast loaded gui for my project. I have decided to go with tkinter. I have installed xorg and some other needed xorg packages, and when I run "startx" I get three windows and a litte clock with some green/blue colored borders and i can move the widows with drag and drop. If I run my tkinter py-file from any window it works just fine.
I came over the "xinit" command and this loads a little faster and just gives me one window without borders. This actually suits me better since my "base window" will work as some kind of desktop and from here I will pop up other windows. Since there's no borders or title bars on the windows, they are not moveable. Is there any way to achieve this? That is, I want just some windows to have a border and a title bar.
And; how can I run the tkinter py-file automatically when I run the xinit/startx? I have tried the other approach by run the xinit/startx in the pyfile, but this does not work. I guess this will be called as some kind of sub command in another thread, or something? Any suggestions how I do this?
I have a python command line script that starts a PyQt Application showing the input of the video device in a little window. Then it starts a curses screen so that the user can control the camera with the keyboard.
After starting the script, the window focus is automatically on the PyQt window. Is there any way to tell PyQt to give up the window focus or curses / the terminal to reclaim it?
I use Linux (Mint Cinnamon) and the solution does not have to be OS independent.
You can try with setFocusPolicy here is the documentation. http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#setFocusPolicy
Hi i was wondering if you could have the comand prompt box pop into the Tkinter window when you start the program? Some thing like:
from Tkinter import *
admin = Tk()
cmd = Cmd(admin)
cmd.pack()
admin.mainloop()
I'm on windows
http://tkinter.unpythonic.net/wiki/CmdTkHere is what you want, this is not just opening a cmd window. its embedding cmd.exe into a Tkinter.Frame. And a note here if you rename the python script to ".pyw" extension, the console will be hidden. Except for in a virtual environment's.
I don't believe there is any built in console widget. It may be possible to whip up a custom one using the Tkinter Text widget. However, that would take a bit of effort/time.
Another possible option is simply have your program launch command prompt.
Two different ways to launch command prompt on a Windows machine.
import subprocess, os
subprocess.Popen('cmd.exe')
os.system("cmd.exe")
EDIT:
Unforunetly I don't believe there is any built in widget like that. However I thought of another possible solution, check out the code for the IDLE GUI, it has a console and the GUI portion is entirley written using Tkinter. So you may be able to utelize that code.