【问题标题】:Qt window reopens after being closedQt窗口关闭后重新打开
【发布时间】:2021-03-04 21:53:58
【问题描述】:

我创建了一个按钮来从 PC 浏览数据(打开 PC 文件并浏览)。窗口第一次正常打开,然后当我关闭它时,窗口再次打开。

我该怎么办?

代码:

class second (QDialog):
    def __init__(self):
        super(second,self).__init__()
        loadUi("tt3.ui",self)
        self.pushButton2.clicked.connect(self.pushButton2_handler)
        self.pushButton2.clicked.connect(self.pushButton2_open) #1

    def pushButton2_handler(self):
        print("Button pressed")
        self.pushButton2_open()

    def pushButton2_open(self):
        filename = QFileDialog.getOpenFileName()
        path = filename[0]
        print(path)
  
        try:
            with open(path,"r") as f :
                print(f.readline())
        except IOError:
            print('file not found')
        else :
            print('file is readed')    

【问题讨论】:

  • mmmm,你的问题不清楚,也提供minimal reproducible example
  • 为什么要将两个插槽连接到pushButton2.clicked?这不是很明显会调用pushButton2_open 两次吗?
  • @ekhumoro 谢谢你的留言解决了我的问题 :)

标签: python pyqt5 pyside2


【解决方案1】:

我猜你应该删除这一行

"""self.pushButton2.clicked.connect(self.pushButton2_open) #1"""

【讨论】:

    猜你喜欢
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多