PyCharm + Qt Designer: window closes instantly
The first day I try to deal with the GUI. The problem is that the window instantly closes (or does not open at all) when launched in the Python interpreter from under Windows OS when you double-click on the program file. The .py file association with the Python interpreter is set correctly. Saving as .pyw does not change anything. In debug mode in PyCharm and when launched via the Windows console, the program opens and closes correctly. This does not happen with files that work on the command line and use the input() function. Also, when typing the python -v command, a long report is issued, it’s not clear why, maybe this is the problem?
import sys
from PyQt5 import QtWidgets, uic
counter = 0
class MainForm(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
uic.loadUi('MainForm.ui', self)
self.IncBtn.clicked.connect(self.evt_inc_btn_clicked)
def evt_inc_btn_clicked(self):
global counter
counter += 1
self.CounterLbl.setText('Количество нажатий: ' + str(counter))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
MainWind = MainForm()
MainWind.show()
sys.exit(app.exec_())
A lot of things, nothing helps. I want a GUI application to run in Windows when double-clicking the left mouse button on a file with .py code.
MainForm.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainForm</class>
<widget class="QMainWindow" name="MainForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
<string>MainForm</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="CounterLbl">
<property name="geometry">
<rect>
<x>140</x>
<y>40</y>
<width>231</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Количество нажатий: 0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="IncBtn">
<property name="geometry">
<rect>
<x>210</x>
<y>130</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Inc +1</string>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>



Comments
Post a Comment