gpt4 book ai didi

当我点击按钮两次时,Python 网格布局小部件变得很奇怪

转载 作者:行者123 更新时间:2023-12-01 07:22:24 26 4
gpt4 key购买 nike

**-已解决-**

你好,我最近做了一个程序,它获取imdb api(非官方的)并生成bbcode

您可以在这里看到我的代码:pastebin

    def _search(self):
if self.inputBox.text() != '':
srchRes = json.load(urllib.request.urlopen('http://www.omdbapi.com/?apikey=2ee068f3&s='+self.inputBox.text().replace(" ", "%20")))
if srchRes['Response'] == 'True':
self.info.hide()
self.title1.show()
self.title1.setText(srchRes['Search'][0]['Title'] + ' (' + srchRes['Search'][0]['Type'].capitalize() + ' ' + srchRes['Search'][0]['Year'] + ')')
self.sel1.show()
if int(srchRes['totalResults']) > 1:
self.title2.show()
self.title2.setText(srchRes['Search'][1]['Title'] + ' (' + srchRes['Search'][1]['Type'].capitalize() + ' ' + srchRes['Search'][1]['Year'] + ')')
self.sel2.show()
else:
self.title2.hide()
self.sel2.hide()
self.title3.hide()
self.sel3.hide()
self.title4.hide()
self.sel4.hide()
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 50))
Dialog.resize(600, 150)
return
if int(srchRes['totalResults']) > 2:
self.title3.show()
self.title3.setText(srchRes['Search'][2]['Title'] + ' (' + srchRes['Search'][2]['Type'].capitalize() + ' ' + srchRes['Search'][2]['Year'] + ')')
self.sel3.show()
else:
self.title3.hide()
self.sel3.hide()
self.title4.hide()
self.sel4.hide()
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 100))
Dialog.resize(600, 200)
return
if int(srchRes['totalResults']) > 3:
self.title4.show()
self.title4.setText(srchRes['Search'][3]['Title'] + ' (' + srchRes['Search'][3]['Type'].capitalize() + ' ' + srchRes['Search'][3]['Year'] + ')')
self.sel4.show()
else:
self.title4.hide()
self.sel4.hide()
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 150))
Dialog.resize(600, 250)
return
if int(srchRes['totalResults']) > 4:
self.title5.show()
self.title5.setText(srchRes['Search'][4]['Title'] + ' (' + srchRes['Search'][4]['Type'].capitalize() + ' ' + srchRes['Search'][4]['Year'] + ')')
self.sel5.show()
else:
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 200))
Dialog.resize(600, 300)
return
if int(srchRes['totalResults']) > 5:
self.title6.show()
self.title6.setText(srchRes['Search'][5]['Title'] + ' (' + srchRes['Search'][5]['Type'].capitalize() + ' ' + srchRes['Search'][5]['Year'] + ')')
self.sel6.show()
else:
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 250))
Dialog.resize(600, 350)
return
if int(srchRes['totalResults']) > 6:
self.title7.show()
self.title7.setText(srchRes['Search'][6]['Title'] + ' (' + srchRes['Search'][6]['Type'].capitalize() + ' ' + srchRes['Search'][6]['Year'] + ')')
self.sel7.show()
else:
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 300))
Dialog.resize(600, 400)
return
if int(srchRes['totalResults']) > 7:
self.title8.show()
self.title8.setText(srchRes['Search'][7]['Title'] + ' (' + srchRes['Search'][7]['Type'].capitalize() + ' ' + srchRes['Search'][7]['Year'] + ')')
self.sel8.show()
else:
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 350))
Dialog.resize(600, 450)
return
if int(srchRes['totalResults']) > 8:
self.title9.show()
self.title9.setText(srchRes['Search'][8]['Title'] + ' (' + srchRes['Search'][8]['Type'].capitalize() + ' ' + srchRes['Search'][8]['Year'] + ')')
self.sel9.show()
else:
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 400))
Dialog.resize(600, 500)
return
if int(srchRes['totalResults']) > 9:
self.title10.show()
self.title10.setText(srchRes['Search'][9]['Title'] + ' (' + srchRes['Search'][9]['Type'].capitalize() + ' ' + srchRes['Search'][9]['Year'] + ')')
self.sel10.show()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 500))
Dialog.resize(600, 600)
else:
self.title10.hide()
self.sel10.hide()
self.gridLayout.setGeometry(QtCore.QRect(20, 80, 560, 450))
Dialog.resize(600, 550)
return
else:
self.title1.hide()
self.sel1.hide()
self.title2.hide()
self.sel2.hide()
self.title3.hide()
self.sel3.hide()
self.title4.hide()
self.sel4.hide()
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
Dialog.resize(600, 100)
else:
self.title1.hide()
self.sel1.hide()
self.title2.hide()
self.sel2.hide()
self.title3.hide()
self.sel3.hide()
self.title4.hide()
self.sel4.hide()
self.title5.hide()
self.sel5.hide()
self.title6.hide()
self.sel6.hide()
self.title7.hide()
self.sel7.hide()
self.title8.hide()
self.sel8.hide()
self.title9.hide()
self.sel9.hide()
self.title10.hide()
self.sel10.hide()
Dialog.resize(600, 100)

上面的代码是我的搜索功能...

每次我输入关键字并单击“搜索”按钮时,它似乎运行良好,但单击该按钮两次会导致网格布局崩溃。我实在没发现问题所在。

任何人都可以查看我的代码并找出问题吗?如果您优化我的代码,那就更感激了..不一定

最佳答案

我的解决方案

使用QtCore.QRect()时,应注意不要设置位置两次。

就我而言,我在第 66 行定义了网格位置,并在函数 _search 中重新定义了它,这导致了问题。所以,当你重新定义时,你应该像这样使用它

QtCore.QRect(0, 0, Horizontal_size, Vertical_size)

希望对其他人有帮助

关于当我点击按钮两次时,Python 网格布局小部件变得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57636143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com