Is there any way way to create multiple screens in Pygame without redrawing to the screen every time. For example, if we want to create a splash screen, then a main menu with buttons. On clicking the 'Start Game' button, it would go to a new screen which is the actual game. What I mean is anything similar to the 'Form' on Visual Studio or the Activites on Android.
Depends on what you mean.
If you mean making multiple windows at the same time, no, you can't do that--it's a limitation of SDL (although you CAN fake it by using multiprocessing (not multithreading)).
If you mean changing one screen around, yes, you can do that, with multiple calls to pygame.display.set_mode(...). You can change the resolution, arguments, etc. If you're doing OpenGL stuff, that will remake the context too.
If you just mean drawing different things to the same window, of course! That's sorta the point of PyGame.
Other than that, you'll have to clarify.
Just fill the screen with white and then draw the second screen onto the main screen. Then when you need the other screen, just refill the screen with black and then continue. It would help if both of your screens a function and you used a key like tab to "switch" between screens.
Related
I'm trying to change the titlebar color of my pygame window. Because I need to have the background white, but the titlebar is also white. Everyone says to just hide the titlebar.
That's not possible because
I need to be able to close the program with the x button,
I want to be able to move the window,
I want to see the tite and the logo,
Its just much prettier.
Unfortunately, it is not possible to change the titlebar a pygame window; that area is beyond the control of pygame. As you already know, you can hide it and draw your own, but then you lose the quit button and the drag functionality and would have to implement them yourself. And yes, both functionalities are possible to implement if you really want to.
What I want to achieve:
I want to detect the situation when the user is dragging a file over the Kivy app window.
What I already know:
I know how to detect hovering mouse coursor over widgets (with on_mouse_pos), I also know how to detect if a file is dropped onto the window (with on_file_drop).
So, is it possible to see whether the cursor is hovering over the window and "holding" a file? Because then I want to display some prompt (eg. 'Drop HERE'). I hope you get the idea :)
I'm not really sure, because there's this thing with SDL2 (and probably even with old pygame) when the Window just pauses (try some animation or something) when you e.g. drag it with the window decoration (the thing where title and _ O X are). That is the behavior if you do something with the Window directly.
Although, the Window looks like it behaves normally (doesn't pause itself), when you drag file on top of it (I tried with examples/animation/animate.py), to do such thing you'd need to do either the hovering behavior + handling the collisions or bind to mouse_pos.
However, when binding to mouse_pos, it seems like the Window still isn't capable of handling the input from outside and at the same time get mouse properties correctly (I think it's similar to the behavior when you click & drag outside of the Window and Button remains pressed, but this is kind of inversed).
edited animate.py:
class TestApp(App):
def on_mouse_pos(self, win, args):
print args
...
def build(self):
...
from kivy.core.window import Window
Window.bind(mouse_pos=self.on_mouse_pos)
return button
Therefore if you can't get even mouse position when a mouse button is being held, I don't think such an action is possible. You can however make the areas where you want to drop the file already different (e.g. change background) when you'll expect a user to drop the file - a very dirty workaround from UI side for such a problem.
Side note: Kivy should be able to get most (if not all) SDL2 window events via Cython, therefore if you find such event in SDL2 that would make fetching mouse position possible, such action could be performed, feel free to make a feature request in kivy/kivy or make a pull request.
Pressing command-H in OSX immediately hides the active window. How do I achieve the same effect, programmatically, from Python? Specifically, I'd like to find a particular window that my application creates and then be able to show & hide it programmatically.
I already know how to do this with pywin32 but I'm afraid my expertise there doesn't quite cover OSX as well.
If it helps, the window in question is one created by pygame. I know that pygame has pygame.display.iconify() but that doesn't satisfy my requirements - the window doesn't disappear immediately, but rather the disappearance is animated, and there's no corresponding "uniconify" function that I can find.
Well, this ended up working. When I want to hide the window, I do pygame.display.quit() and make my code properly handle not having a display. When I want to show it, I do pygame.display.set_mode(...) with the former resolution.
The net effect is that of hiding & showing the window. Unfortunately the window gets created in a different spot than where it started, and although apparently you can tell SDL to create the window in a particular spot, I haven't been able to find a way to get the window's location...
I was wondering how I would undo drawing steps in Python/Pygame.
Basically I have made the mouse draw lines, and when I click my undo Rect, I want the screen to revert back to its original state (before mouse was pressed).
Here is my code but it does not work well.
copy=screen.copy()
if undoRect.collidepoint(mx,my) and mb[0]==1:
screen.blit(copy,(0,0))
if mb[0]==1 and omb[0]==1:
draw.line(screen,color,(omx,omy),(mx,my),5)
can someone who knows what I mean please give me ideas on how to make an undo last drawing button?
Thank you.
Ps. I am fairly new to pygame/python so please go a little slowly.
You just need to save the frames when the user interacts with the application.
For example in a demo paint application I wrote with opengl I used a list with 20 elements max and I was updating it when the user started a new action.
If user clicks to the screen, save the current frame to the list. If user stop clicking save the new frame. Then, when you need to go back you just have to take the last element of your list and draw it to the screen.
I would like to create an application that has 3-4 frames (or windows) where each frame is attached/positioned to a side of the screen (like a task bar). When a frame is inactive I would like it to auto hide (just like the Windows task bar does; or the dock in OSX). When I move my mouse pointer to the position on the edge of the screen where the frame is hidden, I would like it to come back into focus.
The application is written in Python (using wxPython for the basic GUI aspects). Does anyone know how to do this in Python? I'm guessing it's probably OS dependent? If so, I'd like to focus on Windows first.
I don't do GUI programming very often so my apologies if this makes no sense at all.
As far as I know, there's nothing built in for this.
When the window is hidden, do you want it completely invisible or can a border of a few pixels be showing? That would be an easy way to get a mouse hover event. Otherwise you might have to use something like pyHook to get system-wide mouse events to know when to expand your window.
The events EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW might also be useful here to know when the user has entered/left the window so you can expand/collapse it.
Expanding/collapsing can just be done by showing/hiding windows or resizing them. Standard window functions, nothing fancy.
By the way, you might want to use wx.ClientDisplayRect to figure out where to position your window. That will give you a rectangle of the desktop that does NOT include the task bar or any other toolbars the user has, assuming you want to avoid overlapping with those things.
Personally, I would combine the EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW that FogleBird mentioned with a wx.Timer. Then whenever it the frame or dialog is inactive for x seconds, you would just call its Hide() method.
I think you could easily just make a window that is the same size as the desktop then do some while looping for an inactivity variable based on mouse position, then thread off a timer for loop for the 4 inactivity variables. I'd personally design it so that when they reach 0 from 15, they change size and position to become tabular and create a button on them to reactivate. lots of technical work on this one, but easily done if you figure it out