Dears,
I learned today how to use virtualenv for my python projects. Now I started my pygame file from virtualenv via terminal "python mygame.py" and it worked, however I cannot play the actual game. When I move to the pygame window and hit any key, the output continues being displayed in the terminal. How can I switch to the actual pygame window and play the game while I am in the virtualenv?
Thank you
Related
I am trying to run a python file for a snake game in PyCharm (Community Edition 2020.2). I am using Python 3.8. When I try to run the file, the Python application tries to open, but is never able to to start the game. I feel like there is something wrong with my interpreter. I used the "which python3" command to figure out where my Python3 was installed and am using that location for my interpreter, but again, the application doesn't open upon running. I have attached a screenshot of my interpreter. Any thoughts on what might be wrong would be great
PyCharm automatically creates a virtual env for your work. That might be the root of your problem. You could look up about that to resolve your problem. I am a bit less familar with virtual-envs. Someone else could give you detailed info but it might be the gist.
I'm working through Think Python chapter 4, where they tell you to type the following to see if you have the turtle module:
import turtle
bob = turtle.Turtle()
This is supposed to open a new window, but instead, it crashes my computer. I've seen it freeze my computer where I can't move the cursor or change windows, and I have to restart it. And I've also seen it close all my programs and re-open them.
I'm running Python 3.7 downloaded from Anaconda on a Macbook Air with Mojave version 10.14.6.
EDIT: When I run BenajahTX's suggestion below, I get this error message printed 16 times:
CGSTrackingRegionSetIsEnabled returned CG error 268435459
Any clue what is causing this or how to fix it?
try and set the screen and mainloop
window = turtle.Screen()
window.setup(width,height)
while True:
window.update()
window.mainloop()
Try running the file in the terminal using the command:-
$ python filename.py
I had the same issue and I was VS code extension Code Runner to run the python file, however, when I tried the terminal it worked and the mac OS was not crashing this time
When running pygame in Ubuntu a terminal is opened along with the pygame window. I want to get rid of the terminal. I can launch pygame with nohup and &:
$ nohup python3 mygame.py &
This allows the terminal to be closed, but it does not prevent it from being opened in the first place.
Is there a way to run pygame without a terminal being opened?
The OP explains that one should create a desktop shortcut,
and the the terminal goes away.
I have written a python game using pygame module. It runs fine from terminal.
I have a game directory (let's call it myGame) which contain all the resources(images and sounds) and all the python scripts which use those.
When I run the game through terminal (let's say python3 mainPythonModule.py), the game runs fine.
I tried to create a game.desktop file. But when I click it, a black window appears and crashes almost instantly.
I am using Ubuntu 16.04 LTS. And my game is written in python3.5 and uses pygame module.
My game.desktop file looks like this
I don't want the solution answered for this question because I still have to type in terminal.
I would like to create a desktop applcation, such that by clicking on the icon, the game would start.
Just like when we download any game, after installation, we just click on the game icon and it runs, I want something like that. How can I do that?
Edit :
I don't think this question is a possible duplicate of this question.
I want to know how to develop a desktop application in Ubuntu 16.04, such that by clicking on some icon, the game would start.
Final Edit :
First of all, I would like to thank everyone who responded. I really am sorry for wasting your precious time.
The issue is resolved. The problem was all the resource (images and sounds) were loaded via relative path and not through absolute path. Now the game.desktop file runs fine.
I think what are you trying to do is some kind of launcher.
Here you have my repo, it contains a Tkinter GUI with a PyGame call on a button.
Feel free to study/use it as you want, look at the file desktop_application.py and if you don`t care about the coin part you can just skip that and take what you need.
https://github.com/FilippoLeone/PyGameLauncher
And you can compile everything as an executable with PyInstaller.
Install PyInstaller from PyPI:
pip install pyinstaller
Go to your program’s directory and run:
pyinstaller yourprogram.py
This window shows up when I attempt to install mtTkinter with "python mtTkinter.py install" through command prompt:
This is the command prompt log from the install:
(Highlighter and added/blue pen area is the log)
I am working on a clicker game, like cookie clicker, and Tkinter tends to freeze when using threading. I found mtTkinter, which is multithreading safe.
So I typed in "python mtTkinter.py install" into command prompt. There is no error, it just does not install. The window that opened had the two buttons, [Click Me!] (which gets square brackets added to it over and over) and then QUIT. The Click Me button does nothing, and the quit button closes it.
I am running Windows Vista Python 2.7.11. What am I doing wrong?
Keep in mind I am a beginner at python and computer science, so please be simple with your answers.
Most tutorials that indicate to run:
python setup.py install
Will use the specific filename setup.py, usually if there is no setup.py the file is usable as it is or needs to be installed manually, in this case the mtTkinter.py file has no need for installation.
The reason you were seeing the startup window is that that is the test app when you run tkinter as the main program (which is what you did) you could see the same popup from the original tkinter by running:
python -m Tkinter
(The -m indicates to run a module) Obviously tkinter is not an installation package and it actually ignored the install argument entirely, it just went to the test app.