How to use Pygame Kivy together?

8,430 views
Skip to first unread message

sakanac...@gmail.com

unread,
Feb 21, 2013, 12:04:00 AM2/21/13
to kivy-...@googlegroups.com
Hi, so I made a game using pygame completely and it works quite well. I'm somewhat new to programming but i'd like to try this on android, so I figured that i'd try to integrate Kivy into my code seeing that it looks so promising. My first plan of action was to at least get a button (from kivy) onto my game's screen. But sadly I keep running into an issue. When i try to run my game, the entire block of code starts, but when it reaches the point where i have to return the widget (which creates a Kivy window), then my entire game crashes. I've been reading some of the documentation and the tutorials, but I really have no idea on how to start on converting my pygame code using Kivy.

I guess at the very least i'd like to know how to get my original Window: "thescreen=pygame.display.set_mode((0,0),pygame.FULLSCREEN) " to stop displaying; And instead let the Kivy Window display, and let me do all the drawing on that Kivy window instead. Right now the variable for my Pygame's window is thescreen. How would i go about doing my drawing on the Kivy window instead? Is there a way that i can set Kivy's window to thescreen?

I fear that maybe i will have to re-write EVERYTHING in Kivy and i can't implement my pygame code at all....
If you need any more details and I haven't supplied enough just let me know! I'm sure my interpretation of Kivy and it's integration with Pygame is completely wrong, but i just wanted to get my problem out there and let you guys know how i was thinking.
I'll be checking back constantly! Thank you!

Gabriel Pettier

unread,
Feb 21, 2013, 4:45:32 AM2/21/13
to kivy-...@googlegroups.com
Hi

kivy and pygame works very differently, and i don't think mixing them is
really possible, you may be more interested in PGS4A if rewriting (most
of) your code is not an option for you.

If you want to mix both, you have to understand that in pygame, you draw
directly on the screen object, you do clear/bits/updates there with your
various textures of ingame objects every frame. In kivy, you place
widgets on the screen, these objects have canvas, that are persistant,
you shouldn't erase everything and redraw it every frame, you could
decide to just put one widget at the bottom of your widget tree, and
draw all of your current game on it, but that's not how you usually use
kivy.

To help us help you, maybe giving a set of snippets of how you currently
do your things with pygame, so we can try to come up with equivalences,
no promise, though, since as said, the fundamental way of working with
kivy is different of the one of pygame.

regards

On Wed, Feb 20, 2013 at 09:04:00PM -0800, sakanac...@gmail.com wrote:
> Hi, so I made a game using pygame completely and it works quite well. I'm
> somewhat new to programming but i'd like to try this on android, so I
> figured that i'd try to integrate Kivy into my code seeing that it looks so
> promising. My first plan of action was to at least get a button (from kivy)
> onto my game's screen. But sadly I keep running into an issue. When i try
> to run my game, the entire block of code starts, but when it reaches the
> point where i have to return the widget (which creates a Kivy window), then
> my entire game crashes. I've been reading some of the documentation and the
> tutorials, but I really have no idea on *how* to start on converting my
> pygame code using Kivy.
>
> I guess at the very least i'd like to know how to get my original Window: "*
> thescreen*=pygame.display.set_mode((0,0),pygame.FULLSCREEN) " to stop
> displaying; And instead let the Kivy Window display, and let me do all the
> drawing on that Kivy window instead. Right now the variable for my Pygame's
> window is *thescreen*. How would i go about doing my drawing on the Kivy
> window instead? Is there a way that i can set Kivy's window to *thescreen*?
>
> I fear that maybe i will have to re-write EVERYTHING in Kivy and i can't
> implement my pygame code at all....
> If you need any more details and I haven't supplied enough just let me
> know! I'm sure my interpretation of Kivy and it's integration with Pygame
> is completely wrong, but i just wanted to get my problem out there and let
> you guys know how i was thinking.
> I'll be checking back constantly! Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

sakanac...@gmail.com

unread,
Feb 21, 2013, 10:31:07 AM2/21/13
to kivy-...@googlegroups.com
Ohh, alright! This is good enough information for me, I was looking for some insight on how the two work together. If it's as you say then i'll probably rewrite it using Kivy, i've done a few more tutorials and have been getting the hang of it. Thank you very much! If I need any help changing my current pygame code into that of Kivy type, then i'll be back on the forums.

Thanks again

Fernando Coelho

unread,
Feb 22, 2013, 12:10:10 PM2/22/13
to kivy-...@googlegroups.com
This is not kivy related, but if you want to port your game to android there is a pygame subset for android, here is the link http://pygame.renpy.org/ (please notice that I have no idea if this works properly, I have only seen people using it in the game dev community).

Aidan Bailey

unread,
May 8, 2013, 10:21:02 PM5/8/13
to kivy-...@googlegroups.com
I just Checked. Kivy comes with pygame 1.9.2. 

Mathieu Virbel

unread,
May 9, 2013, 3:31:01 AM5/9/13
to kivy-...@googlegroups.com
We might use pygame internally (image loading, ttf rendering, ...), but
that's all. You, as an user, cannot draw anything with pygame on kivy.
Both are incompatible. Use the renpy project, or migrate to kivy!

Mathieu

Le 09/05/2013 04:21, Aidan Bailey a �crit :
>
>
> On Wednesday, 20 February 2013 23:04:00 UTC-6, sakanac...@gmail.com wrote:
>
> Hi, so I made a game using pygame completely and it works quite
> well. I'm somewhat new to programming but i'd like to try this on
> android, so I figured that i'd try to integrate Kivy into my code
> seeing that it looks so promising. My first plan of action was to at
> least get a button (from kivy) onto my game's screen. But sadly I
> keep running into an issue. When i try to run my game, the entire
> block of code starts, but when it reaches the point where i have to
> return the widget (which creates a Kivy window), then my entire game
> crashes. I've been reading some of the documentation and the
> tutorials, but I really have no idea on _how_ to start on converting
> my pygame code using Kivy.
>
> I guess at the very least i'd like to know how to get my original
> Window:
> "*thescreen*=pygame.display.set_mode((0,0),pygame.FULLSCREEN) " to
> stop displaying; And instead let the Kivy Window display, and let me
> do all the drawing on that Kivy window instead. Right now the
> variable for my Pygame's window is *thescreen*. How would i go about
> doing my drawing on the Kivy window instead? Is there a way that i
> can set Kivy's window to *thescreen*?
>
> I fear that maybe i will have to re-write EVERYTHING in Kivy and i
> can't implement my pygame code at all....
> If you need any more details and I haven't supplied enough just let
> me know! I'm sure my interpretation of Kivy and it's integration
> with Pygame is completely wrong, but i just wanted to get my problem
> out there and let you guys know how i was thinking.
> I'll be checking back constantly! Thank you!
>
>
>
>
> I just Checked. Kivy comes with pygame 1.9.2.
>

Luis Bill

unread,
Jun 21, 2013, 2:24:28 PM6/21/13
to kivy-...@googlegroups.com
I have a similar problem.

But for me, I want to display the pygame window and kivy window at the same time (so they are both in separate windows).
I have imported my kivy module into my pygame program, but when I run the program, I can only display one window at a time. For instance, if I use the runClient() function (of pygame) before I run the run() function of kivy, then only the kivy window will be displayed (because run() was the last function that ran in the loop). And this is vice-versa as well.

So how can I get to display both windows at once?

Thank you very much!

Brian MacDiarmuide

unread,
May 12, 2014, 5:18:56 PM5/12/14
to kivy-...@googlegroups.com
Can someone tell me please, in light of all the above, whether you can do everything with kivy that you could do with pygame? I'm not asking whether they are identical in this context, but just in general, ignoring some inevitable differences, are the possibilities as far as game development is concerned in any way equivalent? Are there any disadvantages to using kivy over pygame for creating games?


Alexander Taylor

unread,
May 12, 2014, 8:12:20 PM5/12/14
to kivy-...@googlegroups.com
> Can someone tell me please, in light of all the above, whether you can do everything with kivy that you could do with pygame?

In general terms, absolutely. But kivy has a very different kind of api to pygame - pygame is about blitting textures to the screen, but kivy exposes more of a wrapper around opengl and encourages some different ways of working. It's certainly perfectly well suited to many kinds of games (and other apps). Specific tasks or mechanisms may be easier or harder in kivy.


> are the possibilities as far as game development is concerned in any way equivalent?

Ultimately yes, but I'll stress that the api is in many ways quite different. For this kind of broad question I recommend trying both kivy and pygame - do a few tutorials, and think about how to structure your own app. This will help you to understand what's the same or different in the way that discussion alone simply can't. You could, for instance, compare kivy's pong tutorial to a pygame equivalent.


> Are there any disadvantages to using kivy over pygame for creating games?

Probably, but nothing springs to mind as an 'everyone will care about this' issue. I know a lot more about kivy than pygame though, so it's a lot easier for me to think of things that kivy can do but pygame can't!
Reply all
Reply to author
Forward
0 new messages