RE: Can anyone tell me if pygame and Tkinter can work together?

Discussion in 'Python' started by Nathan Pinno, Nov 16, 2005.

  1. Nathan Pinno

    Nathan Pinno Guest

    Sounds good, I'll give it a try and see what happens, and report back about
    my results.


    Nathan Pinno,
    Owner/operator of The Web Surfer's Store.
    http://www.the-web-surfers-store.com/
    MSN Messenger:
    Yahoo! Messenger: spam_swatter31
    AIM: f3mighty
    ICQ: 199020705

    -----Original Message-----
    From: [mailto:]
    Sent: November 15, 2005 8:47 PM
    To: Nathan Pinno
    Cc:
    Subject: Re: Can anyone tell me if pygame and Tkinter can work together?

    On Tue, Nov 15, 2005 at 06:33:40PM -0700, Nathan Pinno wrote:
    > Thanks. I was going to use TKInter to pop up a message box, then use
    > pygame to run the game and display the score on the playing surface.
    > Is this still possible (I'm using Python 2.4.1 and Pygame 1.7.0 on
    > WinXP with Service Pack 2)?


    This is more likely to work than the scenario I first considered, where both
    GUI libraries would be in use at the same time.

    With my understanding of how X works, and my knowledge of Tk, you'd probably
    be successful if what you want to do is first use GUI Library A, and then
    GUI Library B. This resolves the issue with XSetErrorHandler, for instance,
    because you'll be completely done with Library A at the time you call the
    initialization routines of Library B. It also resolves the event loop
    problem, because you never need to allow Libraries A and B to receive events
    during the same phase of the program.

    I don't know anything about Windows, and I haven't actually given this
    scenario a try on Linux either, so it's still all idle speculation on my
    part. Actual experimentation on your part wouldn't be that hard, though.
    Just write the simplest possible Tk program as a callable function 't()' and
    the simplest possible pygame program as a callable function 'p()', and then
    see what happens when you run them back to back:
    def t():
    import Tkinter
    t = Tkinter.Tk()
    Tkinter.Button(t, command = t.destroy).pack()
    t.mainloop()
    def p():
    likewise
    t()
    p()

    Jeff
     
    Nathan Pinno, Nov 16, 2005
    #1
    1. Advertising

  2. Nathan Pinno

    Nathan Pinno Guest

    It worked, but unfornately I can't use this line as it brings up errors:

    from Tkinter (or pygame) import *

    Anyway around this little bug?

    --
    For great sites go to: http://www.the-web-surfers-store.com
    MSN Messenger: falcon3166@hotmail,com
    Yahoo! Messenger: spam_swatter31
    ICQ: 199020705
    AIM: f3mighty
    "Nathan Pinno" <> wrote in message
    news:...
    > Sounds good, I'll give it a try and see what happens, and report back
    > about
    > my results.
    >
    >
    > Nathan Pinno,
    > Owner/operator of The Web Surfer's Store.
    > http://www.the-web-surfers-store.com/
    > MSN Messenger:
    > Yahoo! Messenger: spam_swatter31
    > AIM: f3mighty
    > ICQ: 199020705
    >
    > -----Original Message-----
    > From: [mailto:]
    > Sent: November 15, 2005 8:47 PM
    > To: Nathan Pinno
    > Cc:
    > Subject: Re: Can anyone tell me if pygame and Tkinter can work together?
    >
    > On Tue, Nov 15, 2005 at 06:33:40PM -0700, Nathan Pinno wrote:
    >> Thanks. I was going to use TKInter to pop up a message box, then use
    >> pygame to run the game and display the score on the playing surface.
    >> Is this still possible (I'm using Python 2.4.1 and Pygame 1.7.0 on
    >> WinXP with Service Pack 2)?

    >
    > This is more likely to work than the scenario I first considered, where
    > both
    > GUI libraries would be in use at the same time.
    >
    > With my understanding of how X works, and my knowledge of Tk, you'd
    > probably
    > be successful if what you want to do is first use GUI Library A, and then
    > GUI Library B. This resolves the issue with XSetErrorHandler, for
    > instance,
    > because you'll be completely done with Library A at the time you call the
    > initialization routines of Library B. It also resolves the event loop
    > problem, because you never need to allow Libraries A and B to receive
    > events
    > during the same phase of the program.
    >
    > I don't know anything about Windows, and I haven't actually given this
    > scenario a try on Linux either, so it's still all idle speculation on my
    > part. Actual experimentation on your part wouldn't be that hard, though.
    > Just write the simplest possible Tk program as a callable function 't()'
    > and
    > the simplest possible pygame program as a callable function 'p()', and
    > then
    > see what happens when you run them back to back:
    > def t():
    > import Tkinter
    > t = Tkinter.Tk()
    > Tkinter.Button(t, command = t.destroy).pack()
    > t.mainloop()
    > def p():
    > likewise
    > t()
    > p()
    >
    > Jeff




    --

    ..............................................................
    > Posted thru AtlantisNews - Explore EVERY Newsgroup <
    > http://www.AtlantisNews.com -- Lightning Fast!!! <
    > Access the Most Content * No Limits * Best Service <
     
    Nathan Pinno, Nov 16, 2005
    #2
    1. Advertising

  3. On 16/11/05, Nathan Pinno <> wrote:
    > It worked, but unfornately I can't use this line as it brings up errors:
    >
    > from Tkinter (or pygame) import *
    >
    > Anyway around this little bug?


    What's the error?

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Nov 16, 2005
    #3
  4. Nathan Pinno

    Nathan Pinno Guest

    It's a warning that says:

    Can only use * in top level or something like that.

    It's kind of annoying, but the program still ran after I made the import *
    lines top level, and removed the def's.

    Nathan Pinno.

    --
    For great sites go to: http://www.the-web-surfers-store.com
    MSN Messenger: falcon3166@hotmail,com
    Yahoo! Messenger: spam_swatter31
    ICQ: 199020705
    AIM: f3mighty
    "Simon Brunning" <> wrote in message
    news:...
    On 16/11/05, Nathan Pinno <> wrote:
    > It worked, but unfornately I can't use this line as it brings up errors:
    >
    > from Tkinter (or pygame) import *
    >
    > Anyway around this little bug?


    What's the error?

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/



    --

    ..............................................................
    > Posted thru AtlantisNews - Explore EVERY Newsgroup <
    > http://www.AtlantisNews.com -- Lightning Fast!!! <
    > Access the Most Content * No Limits * Best Service <
     
    Nathan Pinno, Nov 16, 2005
    #4
  5. Nathan Pinno wrote:

    > It's a warning that says:
    >
    > Can only use * in top level or something like that.
    >
    > It's kind of annoying


    why? importing tons of unknown stuff into a local namespace is
    rather silly, and makes it impossible for the compiler to properly
    analyze your code -- which means that you cannot use nested
    scoping. the language reference says:

    The from form with "*" may only occur in a module scope.
    If the wild card form of import -- "import *" -- is used in a
    function and the function contains or is a nested block with
    free variables, the compiler will raise a SyntaxError.

    future versions of Python will most likely issue a SyntaxError also
    for "import *" in non-nested functions.

    > but the program still ran after I made the import * lines top level,
    > and removed the def's.


    moving the "import *" line to the module scope would have been
    enough; functions can refer to module-level variables just fine.

    you might wish to read up on Python scoping rules:

    http://docs.python.org/ref/naming.html

    </F>
     
    Fredrik Lundh, Nov 16, 2005
    #5
  6. Nathan Pinno

    Nathan Pinno Guest

    Even its from one or two external libraries like Tkinter and pygame? I
    prefer to load what I need, not to constantly have to call it by its library
    dot its_name. It makes easier coding for me. I try to keep my code as simply
    as possible. Wonder if its possible to use a Tkinter question to make a
    pygame run again (example being you get killed on a level and you want to
    play again without exiting)?

    --
    For great sites go to: http://www.the-web-surfers-store.com
    MSN Messenger: falcon3166@hotmail,com
    Yahoo! Messenger: spam_swatter31
    ICQ: 199020705
    AIM: f3mighty
    "Fredrik Lundh" <> wrote in message
    news:...
    > Nathan Pinno wrote:
    >
    >> It's a warning that says:
    >>
    >> Can only use * in top level or something like that.
    >>
    >> It's kind of annoying

    >
    > why? importing tons of unknown stuff into a local namespace is
    > rather silly, and makes it impossible for the compiler to properly
    > analyze your code -- which means that you cannot use nested
    > scoping. the language reference says:
    >
    > The from form with "*" may only occur in a module scope.
    > If the wild card form of import -- "import *" -- is used in a
    > function and the function contains or is a nested block with
    > free variables, the compiler will raise a SyntaxError.
    >
    > future versions of Python will most likely issue a SyntaxError also
    > for "import *" in non-nested functions.
    >
    >> but the program still ran after I made the import * lines top level,
    >> and removed the def's.

    >
    > moving the "import *" line to the module scope would have been
    > enough; functions can refer to module-level variables just fine.
    >
    > you might wish to read up on Python scoping rules:
    >
    > http://docs.python.org/ref/naming.html
    >
    > </F>
    >
    >




    --

    ..............................................................
    > Posted thru AtlantisNews - Explore EVERY Newsgroup <
    > http://www.AtlantisNews.com -- Lightning Fast!!! <
    > Access the Most Content * No Limits * Best Service <
     
    Nathan Pinno, Nov 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erik  Bethke
    Replies:
    3
    Views:
    844
    Erik Bethke
    Jan 19, 2005
  2. Nathan Pinno
    Replies:
    1
    Views:
    392
  3. rantingrick

    [pygame-bug] Pygame.cdrom bug

    rantingrick, Jan 30, 2011, in forum: Python
    Replies:
    1
    Views:
    338
    Benjamin Kaplan
    Jan 30, 2011
  4. D. Alvarado

    Can anyone tell me a Mac IE work-around?

    D. Alvarado, Apr 26, 2004, in forum: Javascript
    Replies:
    0
    Views:
    89
    D. Alvarado
    Apr 26, 2004
  5. Replies:
    5
    Views:
    105
    apatheticagnostic
    May 8, 2008
Loading...

Share This Page