【发布时间】: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 谢谢你的留言解决了我的问题 :)