Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

python - Is there anything I need aware of using Tkinter and pygame together?

I am using pygame to write a program and I need some GUI configuration text field and button for control. I've already made the button using pygame, but I just can write a text field out of pygame. Maybe I need to use tkinter together with pygame.

I think if there is no way to made to pygame part and tkinter part together in 1 window, then I could put them into 2 separate windows.

I hope the tkinter part can update the global variable in my pygame part, would there if any problem? I might create a child process of tkinter from the pygame part so that the tkinter part can probably "see" the global variable in pygame part and modify them.

Can I do this? Are there any pitfalls?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Both Tkinter and Pygame have their own event loops, so doing what you want is far from simple. The problem is that Pygame wants to control both the screen and the events the user feeds into the computer. This doesn't work well with GUI libraries, which also want to be "in control".

I would suggest sticking with Pygame, it has some nice GUI toolkits that will help you create buttons and other controls. Go over this page - it should clear things out. You may also find this discussion useful.

Apart from the practical aspects, a GUI created with Pygame is also IMHO more suitable for a game than something done with Tkinter, since games usually have original, thematical user interfaces and not the bland "text box + button" windows we're used to in other applications.

Take a look at some of the sample games on the Pygame wiki, many have GUIs and you can borrow ideas and code from them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...