多个文件中的 PyQt 小部件
我想通过编写一个简单的游戏来学习 PyQt。第一个小部件将具有“新游戏”、“退出”等按钮。我无法理解如何从该菜单小部件转换到新的菜单小部件。
例如,如果我单击“新游戏”,如何出现一个新的小部件来替换旧的小部件并询问用户名?我现在处理它的方式就像
Form = QtGui.QWidget()
ui = uiMainMenu()
ui.setupUi(Form)
Form.show()
一旦按下 newGameButton ,它就会进入一个子例程...
Form2 = QtGui.QWidget()
ui2 = uiNewGame()
ui2.setupUi(Form2)
Form2.show()
我并不要求所有代码,只是解释我应该如何处理这个问题,因为代码以上不是深蹲。
谢谢!
i'd like to learn PyQt by writing a simple game. the first widget would have buttons like "New game", "Quit", etc. i am having trouble understanding how to transition from that menu widget to a new one.
for instance, if i were to click New Game, how do i have a new widget appear that replaces the old one and asks for the user's name? the way i am approaching it now is something like
Form = QtGui.QWidget()
ui = uiMainMenu()
ui.setupUi(Form)
Form.show()
then once newGameButton is pressed it would go to a subroutine...
Form2 = QtGui.QWidget()
ui2 = uiNewGame()
ui2.setupUi(Form2)
Form2.show()
i'm not asking for all the code, just an explanation as to how i should be approaching the problem, because the code above ain't doing squat.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想在表单之间切换,那么你可以使用 QStackedWidget。
您可以在下面找到一个工作示例代码:
如果您只想向用户询问名称,那么您可以使用 QDialog 小部件。
if you want to switch between forms then you can use QStackedWidget.
Below you can find a working sample code:
If you only want to ask the name to the user then you can use a QDialog widget.