You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyQt5主窗口打开第二个窗口闪退问题求助及入门资源咨询

PyQt5 Window Disappearing Issue & Beginner-Friendly Resources

Hey there! Let's fix that annoying disappearing window first, then I'll share some great resources to help you wrap your head around Qt logic and OOP.

Why Your quitto Window Vanishes Immediately

This is a super common pitfall for PyQt beginners: your pippo variable is a local variable inside the QPushButtonQPressed method. As soon as that function finishes running, Python's garbage collector cleans up the variable—and takes your quitto window right along with it.

The Simple Fix

Turn pippo into an instance attribute of your menu class by adding self. before it. This keeps the window object alive as long as your main menu window exists:

def QPushButtonQPressed(self):
    print('buttonB pressed' *5)
    self.pippo = quitto()  # Now it's tied to the menu instance
    self.pippo.show()

That's all you need! Your quitto window will now stay open until you close it manually.

Since you're still building your OOP foundation and find Qt's official docs too dense, here are some approachable picks:

  • PyQt5 Beginner Tutorial Series:These step-by-step guides stick to simple, practical examples covering basic widgets, signal-slot connections, and window management. They skip the jargon and focus on helping you understand how Qt's core logic works.
  • Python GUI Programming with PyQt5 (Book):Starts with OOP basics tailored specifically for PyQt, then builds up to small real-world projects. It explains why Qt relies on OOP patterns, making it easier to connect the dots between classes, widgets, and events.
  • Qt for Python Beginner Guides:Even though it's for PySide2 (a close cousin of PyQt5), the syntax and concepts are nearly identical. These official guides are way more beginner-friendly than the main Qt docs, with clear breakdowns of application loops, window lifecycles, and more.
  • Corey Schafer's PyQt5 Video Tutorials:If you learn better by watching, these videos walk you through building small GUI apps from scratch. Corey breaks down complex ideas like OOP and event loops into easy-to-digest chunks.

内容的提问来源于stack exchange,提问作者pippo1980

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 08:37:28