This question already has answers here:
Why is my PyGame application not running at all?
(2 answers)
Why is nothing drawn in PyGame at all?
(2 answers)
Closed 2 years ago.
Looking at my code there are no errors. I have tried all sorts to try and get my panes to display but they still won't appear. I have retraced all my steps and tried to look for where I may have gone wrong, but to me everything seems fines and should work yet it doesn't.
I currently have 3 different states. State 1 being the main screen which is "10 main boxes" on screen. State 2 being a "virtual keyboard" and state 3 being "set phrases". State 3 is the one that doesn't display the pane/s and I can't understand why.
Here's the main screen:
(The keyboard also works)
Here is what happens when you click set phrases:
A pane/rectangle is meant to appear on the set phrases screen in these co-ordinates sPhraseLoc = [(400, 100, 150, 50)]. It is also meant to have "Hi my name is Dave." written in it. (Look at code below for reference)
Can someone please explain to me why "Hi my name is Dave." isn't appearing on the screen in a pane/rectangle? All help is much appreciated.
Here is the code (It is rather long so I thought that I'd just link it)
I am also suspicious of a part of the code and think the problem lies their but I am not too sure. (Here is the link)
Like I said earlier any help is much appreciated.
Related
This question already has answers here:
Can I detect if a window is partly hidden?
(2 answers)
How to determine if any part of the window is visible to Screen?
(1 answer)
How to get only the visible part of a window (Windows, gdi32, user32, etc)
(2 answers)
Closed 8 months ago.
I want to get a window's clip box so I can detect if the whole window is displayed.
package: win32gui
I know that IsWindowVisible() from the Windows API will return true if a window is NOT minimized, but it won't detect if the window is hidden behind other windows.
I also know that in C++, I could use GetWindowDC(); GetClipBox(); ReleaseDC(); to get a RECT struct with the coordinates of the smallest bounding rectangle of the window (I got this from another post on StackOverflow, but I haven't tested it).
In Python, I can use:
# That just returns a window by the title
handle = getWindowByTitle("Skype") # "Skype" is just an example
winDC = win32gui.GetWindowDC(handle)
# this function doesn't seem to exist/be implemented in win32gui
win32gui.GetClipBox(winDC, '''This also needs a RECT struct''')
win32gui.ReleaseDC(winDC)
How can I use GetClipBox() in Python? Or, is there any other way to check it?
I would like to not use any other package, because I want my app to have as few dependencies as possible.
I have also heard of ctypes, but I have never used them. I am not sure how it works, and/or if it can help here.
This question already has answers here:
Making the background move sideways in pygame
(2 answers)
How to scroll the background surface in PyGame?
(1 answer)
How to move the background image with keys in pygame?
(1 answer)
Closed 2 years ago.
I'm learning Python and trying to improve my skills by creating a little game using Pygame while learning through videos.
Therefore I would like to implements the basics menus, which include a pause menu and a couple more fonctions.
My goal is to have something like this:
Main Menu and level selection:
Game itself
Pause menu with restart/resume/back to main menu.
The problem is that, the more I use the pause menus and the more time passes, the more the main menu become visually glitched.
The visual glitch also don't seems to have a regular patter, sometimes it's the ship that stick, sometime the enemies or the lasers, or all of them at once.
The main title become also less and less clear with time.
I took some screenshots that you can find here.
I posted most of the useful code here so that you can try it.
The assets that I used can be download with this link if needed:https://techwithtim.net/wp-content/uploads/2020/04/assets.zip
EDIT:
It seems like the problem comes from this part of the code that manage the infinite auto-scrolling of the background image of the in-game loop.
global y
rel_y = y % BACKGROUND.get_rect().height
screen.blit(BACKGROUND, (0,rel_y - BACKGROUND.get_rect().height))
if rel_y < HEIGHT:
screen.blit(BACKGROUND, (0, rel_y))
y += 1
However, if the background is scrolling from the start in the main menu, it doesn't seems like there is any glitch anymore.
I don't really see why it glitched in the first place and I don't really know why making it loop from the start fixed the problem.
What could have made it happend?
(I edited the pastebin with the minimum needed for the code to work, it just need a background image that I can't add, but is on the asset download link if needed)
Firstly, there are a couple of similar questions posted on this. But they are not complete questions, and no one has really answered them all. I am using Python to send input to a game active in widow modes using "ctypes" package. The original idea is mentioned here
In particular, my codes are:
x=500
y=400
for i in range(10):
time.sleep(4)
if i > 0:
x=x+17
pos=(x,y)
#ctypes.windll.user32.SetCursorPos(x,y) # this does not work in game but
#outside the game window
ctypes.windll.user32.mouse_event(0,x,y,0,0)
print i
In order for the "mouse_event" to work, I tried inputting hexadecimal values but can't get it to move consistently. I tried setting up separate class & functions to import, then calling the function. The function works outside the game window but not inside the game window.
The separate class & functions are based on this question
Thank you for your help in advance.
This question already has answers here:
IDLE won't highlight my syntax
(4 answers)
Closed 6 years ago.
Python IDLE Editor doesn't seem to be working for me.
As can be seen in this picture, if, 'hello' and None are all highlighted with different colors when the document is "untitled" (not saved) but as soon as i save the document the colors disapear as can be seen in the picture to the right. Changing custom highlighting doesn't have an effect.
OMG i'm so stupid. While saving i just selected .py without actually typing .py at the end of the file name.
Tried to figure the problem out 30 minutes before asking here then a few seconds after posting relized my mistake
This question already has answers here:
binding to cursor movement doesnt change INSERT mark
(2 answers)
Closed 8 years ago.
I'm making a basic IDE, line numbers are going to be similar to IDLE, but I don't want to bind each possible key to an event which changes the box with the current line/col in it. Is there some kind of "on change", or "one cursor move" event build into Tkinter, or more specifically, ScrolledText. If there isn't then if anyone can point me in the right direction that would be fantastic.
Thanks!
There's nothing built-in per se, but what you want to do is possible if you're willing to be creative.
At it's core a text widget is a tcl command, and this command is called whenever something happens to the text widget: text is inserted, deleted, the cursor changes, etc. The nature of tcl is that we can replace this command with our own command. And since we can do that, we can detect certain changes, and call our own function before or after.
It sounds complicated, and it is. On a positive note, it's foolproof once you have it working, and it means you don't have to do any custom bindings. To see a complete working example, see this answer to the question binding to cursor movement doesnt change INSERT mark.
The scrolled text widget is just a thin wrapper around a regular text widget, so this answer will work with just a tiny bit of tweaking (you'll need the reference to the text widget used by the scrolledtext widget). The wrapper is so thin, however, that I recommend not using it since adding scrollbars to a text widget is trivial.