2 Replies - 1212 Views - Last Post: 16 December 2014 - 02:44 PM Rate Topic: -----

#1 Sodium3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-July 14

pygame tkinter mouse freezing

Posted 16 December 2014 - 08:04 AM

Hi!I made an game in pygame and just finished making score submitting system with Tkinter. However I have a problem.
So the score submitting system works like these:
1.game is finished
2.press s to submit score
3.tkinter inputbox pops up
4.enter your name and click submit
5.input is processed and displayed on screen

I do not have any problem with score submitting system itself but sometimes when tkinter pops up within pygame window mouse becomes frozen and only way to submit score is alt+esc but I can't expect user to do that.Sure I could set pygame window position at beginning and then set tkinter window position somewhere else but what if user moves window?
 if event.key==pygame.K_s:

                    subbox=Tkinter.Tk()
                    subbox.geometry("+0+0")
                    subbox_label=Tkinter.Label(subbox,text="Type your name:")
                    subbox_label.pack()
                    subbox_entry=Tkinter.Entry(subbox)

                    subbox_entry.pack()




                    def savescore(player_score):


                        player_score=str(player_score)                       
                        print player_score 

                        print subbox_entry.get()
                        player_name=subbox_entry.get()

                        namefile=open("name.txt","a")

                        namefile.write(player_name)
                        namefile.write("\n")

                        scorefile=open("score.txt","a")



                        scorefile.write(player_score) 
                        scorefile.write("\n")

                        subbox.destroy()
                        namefile.close()
                        scorefile.close()
                        display_leaderboard()#this is function that sorts names and score and displays leaderboard






                    subbox_button=Tkinter.Button(text="Click",command=lambda:savescore(score))
                    subbox_button.pack()
                    subbox.mainloop()



Is This A Good Question/Topic? 0
  • +

Replies To: pygame tkinter mouse freezing

#2 Mekire   User is offline

  • D.I.C Head

Reputation: 118
  • View blog
  • Posts: 216
  • Joined: 11-January 13

Re: pygame tkinter mouse freezing

Posted 16 December 2014 - 01:13 PM

Although it is possible to use pygame and tkinter together, they really don't play nicely. If you are just trying to get user text input you would be better off just using pygame.
https://github.com/M.../pygame-textbox

If you are set on using tkinter, please supply a short runnable example that recreates your problem and I'll see if I can help.

-Mek
Was This Post Helpful? 0
  • +
  • -

#3 Sodium3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-July 14

Re: pygame tkinter mouse freezing

Posted 16 December 2014 - 02:44 PM

I just fixed problem by making code that breaks pygame loop but not tkinter one. So it's like this:
1.press s
2.
pygame.quit() 
then break loop with setting loop variable to false.
3.tkinter window pops up and asks user for their name
4.when user click submit I run function that opens pygame window and displays leaderboard

Thanks for the link aniway.I'll take a look at it and may use it for other projects :winkiss:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1