I am making turn based game in python using Pyglet. The game has a player-vs-AI mode in which the bot calculates a move to play against the player. However, the function which calculates the bot's move takes around 3-5 seconds to run, blocking the game's UI. In order to get around this, I am running the bot's calculation on a second process using multiprocessing.Process. I got it to work well without blocking the UI, however every time I open the second process to run the function a new Pyglet window opens, then closes again when the process is closed. Is there any way to open a second process in a Pyglet program without a second window opening? Let me know if examples of my code is required, and I will try to come up with similar code to share. Thanks in advance to anyone who can help.
You can fix the problem by moving the initialization of the window inside of the main block
Related
I am searching for a way to close a specific window of a program immediately after it opens. Specifically, I am using the BUFF addon for Overwolf and after every game I play, this annoying overlay window opens up and blocks part of my screen. To close it windows Alt+Tab'ing out, I need to wait 10 seconds (that means if I'm not willing to subscribe to BUFF premium), and Alt+Tab'ing out after every game is just as annoying.
Is there any way that I can run a Python script while I'm playing that closes this window every time it opens immediately? I'm thinking of something that continously searches for a window with a specific name or maybe something that listens for the event of a window opening and then checking its name/title. I don't even know if Python can access these processes, but I guess it's worth to just ask.
And before I need to edit the post, I'm using Windows 11.
I want to make a program stop running for a certain amount of time to save CPU power. I have a self.after function that I want to run to make the program stop running for a set amount of time. However, it always crashes the program.
self.after(int(self.timeSleep*1000),print("Sleeping."))
The word Sleeping. is printed but the window crashes. I thought that Sleeping. should only be printed after the "sleep" was done. I'm not sure what I'm doing wrong and I couldn't find another question like this. Forgive me if it's a stupid mistake as it's my first time using TKinter.
Thanks in advance.
EDIT:
I am not getting any errors in my terminal. By crash I mean the window stops responding.
Your code has the same effect as below:
execute print("Sleeping.")
execute self.after(int(self.timeSleep*1000), None) which is the same as time.sleep(int(self.timeSleep*1000)).
You need to change it to use lambda:
self.after(int(self.timeSleep*1000), lambda: print("Sleeping."))
I found a solution that doesn't require using self.after. Instead, you can use a thread to run this specific method, allowing you to use while loops and time.sleep without crashing the main GUI program.
I have a program that I'm currently using tkinter to pop up a window and use the root.title of the window as a counter. I call this program through subprocess mutliple times, aka multiple windows pop up and display that I only have to look at the counter to see how long before each of the programs is finished running.
I want to know how long before each and every process is finished. Doing a bit of testing I don't believe using subprocess it will report back to IDLE and show a counter using print(). At least it doesn't appear to be doing so right now for me.
Is there any way of accomplishing this same task without using tkinter?
Below is the link to the other open question right now that I'm currently using to open the tkinter window that closes on me unexpectedly. I'm not completely sure when a windows closes if the whole program stops running or if just the windows closes. Hence why I want the counter...hence why I have always been using a tkinter window as I don't know of any other way of doing this that serves the same purpose.
I want the counter so I can tell the program was finished if my internet connection gets dropped. I don't have internet access at home so I'm always using free-wifi which quite often has timeouts on it. I want to know for sure whether the programs have finished running or if I got timedout and need to rerun the program.
Python program terminating unexpectedly
I have code which runs immediately when I run using python. The code has tkinter module and bunch of if statements. I created a standalone executable and it takes about 8 minutes to give the output for the GUI. I was wondering why it takes so much time to run ?
Thanks in advance.
If you do a bunch of work before calling mainloop, you won't see anything appear until you call mainloop or update. The only way a window will appear is in response to an event that asks for the window to be displayed, and tkinter can't process events if mainloop isn't running.
I am writing a code which loads some images and music files for their usage in the code .
Problem is that it goes to not responding state for few seconds when i run program for the first time in windows , I know it should take some time to load images and music however i want to do that without going to not responding state but at a time when i can show a screen named loading and on background all stuff gets loaded and once stuff is loaded program should go further .
Any ideas ?
You should be able to make the splash screen visible, although I am new to kivy so I don't know how. In some SDK you can control when the screen disappears, you could make it disappear after your media are loaded. But sometimes this will mean too long a wait for UI to appear, in that case you are better off doing as #inclement suggests in Remove or replace the kivy splash screen on startup:
make sure your build method doesn't do much, and try to construct as much state as possible only after that.
You would typically load the media in a separate thread that you start from the GUI build method, and you have your thread signal load complete via a callback where you update GUI accordingly. I don't know yet if that is how one is meant to do it in kivy.