我的“程序”的简要说明。当我单击主窗口中的菜单条目时,将打开一个弹出窗口以获取用户输入,触发子帧显示在主窗口中(此窗口直到那时一直处于隐藏状态)。该子帧具有一个按钮,该按钮应创建嵌入在子帧中的另一个帧(另一类的一部分)。问题是单击按钮时它不会显示。我一直在寻找解决方案,但找不到。 预先感谢!
import sys
from PyQt5.Qt import *
from PyQt5.uic import *
class Main_fr(QMainWindow):
def __init__(self):
super().__init__()
self.mainwin = loadUi("Main.ui", self)
self.menu_crnewwin.triggered.connect(self.inputwindow)
self.subWin = loadUi("subwin_Fr.ui", self.mainwin.mainFrame)
self.subWin.createObj.clicked.connect(self.obj_fr)
self.subWin.hide()
self.mainwin.show()
def inputwindow(self):
text, ok = QInputDialog.getText(self, "Input Window", "Some input:")
if ok:
self.subWin_fr()
def subWin_fr(self):
self.subWin.show()
def obj_fr(self):
self.w = Some_obj(self.subWin.objframe, "userentry").gui()
class Some_obj():
def __init__(self, master, userinput):
self.master = master
self.userinput = userinput
self.iterable = loadUi("subsubWin.ui", self.master)
self.iterable.hide()
def gui(self):
self.iterable.show()
def run():
app = QApplication(sys.argv)
GUI = Main_fr()
sys.exit(app.exec_())
run()
主文件:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>df</class>
<widget class="QMainWindow" name="df">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>584</width>
<height>578</height>
</rect>
</property>
<property name="windowTitle">
<string>Fruchtfolge</string>
</property>
<widget class="QWidget" name="mainFrame"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>584</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="menu_crnewwin"/>
<addaction name="open"/>
<addaction name="close"/>
<addaction name="separator"/>
<addaction name="close_prog"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<action name="menu_crnewwin">
<property name="text">
<string>New</string>
</property>
</action>
<action name="open">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="close">
<property name="text">
<string>Close</string>
</property>
</action>
<action name="close_prog">
<property name="text">
<string>Close program</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
子文件:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>761</width>
<height>413</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>option 1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>option 2</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>option 3</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>some text</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="createObj">
<property name="text">
<string>new object</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QWidget" name="objframe" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
subsubwin文件:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>746</width>
<height>48</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>0</number>
</property>
<item row="0" column="23">
<widget class="QWidget" name="widget_28" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="25">
<widget class="QWidget" name="widget_25" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="35">
<widget class="QWidget" name="widget_13" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QWidget" name="widget_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="33">
<widget class="QWidget" name="widget_18" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="28">
<widget class="QWidget" name="widget_15" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="name">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="36">
<widget class="QWidget" name="widget_23" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="27">
<widget class="QWidget" name="widget_26" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="21">
<widget class="QWidget" name="widget_27" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="20">
<widget class="QWidget" name="widget_10" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QWidget" name="widget_8" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="37">
<widget class="QWidget" name="widget_17" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="14">
<widget class="QWidget" name="widget_21" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="22">
<widget class="QWidget" name="widget_11" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="13">
<widget class="QWidget" name="widget_9" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="32">
<widget class="QWidget" name="widget_20" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="31">
<widget class="QWidget" name="widget_19" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="19">
<widget class="QWidget" name="widget_24" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QWidget" name="widget_32" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="16">
<widget class="QWidget" name="widget_30" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="24">
<widget class="QWidget" name="widget_12" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<item>
<property name="text">
<string>some list</string>
</property>
</item>
</widget>
</item>
<item row="0" column="18">
<widget class="QWidget" name="widget_29" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QWidget" name="widget_5" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="QWidget" name="widget_31" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="15">
<widget class="QWidget" name="widget_34" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="30">
<widget class="QWidget" name="widget_16" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="17">
<widget class="QWidget" name="widget_14" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QWidget" name="widget_4" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="26">
<widget class="QWidget" name="widget_7" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="12">
<widget class="QWidget" name="widget_33" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="34">
<widget class="QWidget" name="widget_3" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QWidget" name="widget_6" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QWidget" name="widget_36" native="true"/>
</item>
<item row="0" column="38">
<widget class="QWidget" name="widget" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QWidget" name="widget_35" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="29">
<widget class="QWidget" name="widget_22" native="true">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>background-color: rgb(204, 0, 0);</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_37" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>