I am working with OSX Yosemite. Here is my code:
http://pastebin.com/AWGu37z4
Here is my input file (to run it, just do python myscript.py myinput.txt):
http://pastebin.com/ueaeY0Ss
When I press the s button, a TK window should appear to show an text input box. If I cut and paste the code to just show the window and run it on its own, it works fine. However, if I run it in the middle of the simulation with the pygame window open and running, I get the following error (abort trap 6):
http://pastebin.com/TCwUxjCM
I have no idea on what this could be, nor on how to solve it.
I had the same problem and finally got my program to work by changing the order: the pygame loop has to start after the tk window/mainloop.
I am using macosx mojave 10.14.3 and python3.7 with pygame 1.9.6
Related
I'm just trying to do some of my 100 days of code homework, but since my OS upgraded last night, whenever I try to run a turtle screen (the same code that worked yesterday), the window freezes and I have to shut it down.
Everything ( to my knowledge ) is upgraded and updated in the virtual environment and my computer. ( I use homebrew ). Same freezing screen when code is ran in Idle,pycharm, visual studio code, etc.
Googling around it seems to me an OS issue, has anyone found a workaround? I've tried everything I can find to fix it, but nothing is working. I can't even get an error code because the window freezes and I have to force it to close.
Should I just go back to the last update when everything was working fine?
I use a Mac with Monterey, working on the 100 days challenge and have the same problem.
I did not try to use Turtle with other OS.
I solved half of the problem, by going into Python-Preferences-iPhython Console-Graphics and changing graphics backend to Tkinter.
Now the page does not freeze anymore at the beginning, it opens the screen, executes the code and then when I close the screen I find another frozen screen behind which I can exit only by Force Quit.
I want to take a screenshot with python using pyautogui. This is my code:
import pyautogui
im1 = pyautogui.screenshot("my_screen.png")
My problem is that this way half of my screen is blocked by the python shell, which pops up when I start the code. So the picture doesn´t really is a screenshot. Prior I have used python.exe to run python files and then the problem was the cmd window poping up. Now I use pythonw.exe, because apparently this prevents the cmd window to show up, but now the python shell window blocks my screen.
So does anyone know how I can take a clean screenshot?
Well, the solution was quite simple. After trying to take a screenshot with pillow I got the same result. So the answear is in the configuration of Spyder, which I was using. Under configuration and "run" you can change where the code will run. And I had chosen that the code shall ran in a external window. So I changed to internal and everything works as it should.
make it sleep for 5 seconds maybe? enough to minimize what is not necessary to capture
import pyautogui
pyautogui.sleep(5)
im1 = pyautogui.screenshot("my_screen.png")
I'm writing a tkinter python app that is meant to run on a raspberry pi. When I run the code from the build in IDE on the pi it runs fine and the window opens up, same on IDLE on my windows PC, however when I try and run the program from the command line, it does nothing when I hit enter on the command python3 filename. As well as this, when I enter the python shell from the command line I am able to get a tkinter window to appear using root = Tk(), so I cannot figure out why my program won't run.
I've now fixed this myself so posting the answer in case anyone needs it. My mainloop() function was actually MainPage.mainloop() which for some reason stopped the window from opening from the command prompt...
This question already has answers here:
Problems getting pygame to show anything but a blank screen on Macos
(10 answers)
Closed 2 years ago.
Just started programming in python and pygames.
Whenever I try running a py file with pygames, the pygames window will appear, but there will be absolutely nothing in it. No errors in the log, but nothing shows, it's just a gray screen.
I tried running it on IDLE, and through the command line (I'm on a mac so I use the terminal)
And it's not just my programs that aren't showing anything, I've tried to run one of pygames examples, and it will still not display anything. For example, if I run the pygames alien example, the window will appear with a blank gray background. I'll hear the audio for the program, but no display.
Anything would help, I'm at a loss especially since no errors are showing in the log.
EDIT1:
I'm using Python 3 (and I really need to keep using Python 3)
EDIT2:
I'm using python 3.7. pygames version 1.9.4. The examples are with the pygames, they were downloaded together, so I assume it's for that version.
EDIT3:
ok, my OS is Mojave 10.14. I've tried starting the application by: opening the file, running it on IDLE, and running it through the command line, none have worked. python2 is installed, but when I run the pygame it's a python3 file
Known issue with Mojave - see their issue tracking: https://github.com/pygame/pygame/issues/555
You can also install new pygame using pip install pygame=2.0.0.dev6. This
worked in my case.
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.