对象没有属性 PyQt5 |删除最大化按钮
Object has no attribute PyQt5 | Removing Maximize Button
我正在尝试删除我程序 window 主程序中的最大化按钮,问题是
我收到一个错误统计信息:
'main_window_logic' object has no attribute 'Main_Window'
我可以引用主 window 中的任何对象,我只是不能引用主 window 本身 我使用 Qt Designer 创建 windows.
有什么解释吗?这是使用uic.loadUiType()
引起的吗?
Python(PyQt5)代码:
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys
baseUIClass, baseUIWidget = uic.loadUiType("main_window.ui")
class main_window_logic(baseUIWidget, baseUIClass):
""" Handles Logic for the Main Window (main_window.ui)"""
def __init__(self, parent = None):
super(main_window_logic,self).__init__(parent)
self.setupUi(self)
self.listWidget.setAlternatingRowColors(True)
self.Main_Window.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ui = main_window_logic(None)
ui.show()
sys.exit(app.exec_())
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Main_Window</class>
<widget class="QMainWindow" name="Main_Window">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>930</width>
<height>715</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>930</width>
<height>715</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>4</height>
</size>
</property>
<property name="baseSize">
<size>
<width>4</width>
<height>0</height>
</size>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="windowTitle">
<string>title</string>
</property>
<property name="windowOpacity">
<double>4.000000000000000</double>
</property>
<property name="styleSheet">
<string notr="true">QMainWindow {
background-color: qlineargradient(spread:pad, x1:0.0100548, y1:0.631, x2:0.229627, y2:0.931, stop:0.440607 rgba(97, 35, 86, 255), stop:1 rgba(105, 25, 98, 255));
}
</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>251</width>
<height>661</height>
</rect>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QFrame {
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));
} </string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>251</width>
<height>661</height>
</rect>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QListWidget{
font: 75 11pt "Ubuntu Mono";
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));
;
alternate-background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(226, 24, 24, 255), stop:0.985377 rgba(207, 112, 0, 255));
}
</string>
</property>
<property name="itemAlignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>930</width>
<height>22</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
谢谢。
Main_Window 是顶层,即 window,在您的情况下是通过 self
:
访问的
self.setWindowFlags(
QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint
)
我正在尝试删除我程序 window 主程序中的最大化按钮,问题是 我收到一个错误统计信息:
'main_window_logic' object has no attribute 'Main_Window'
我可以引用主 window 中的任何对象,我只是不能引用主 window 本身 我使用 Qt Designer 创建 windows.
有什么解释吗?这是使用uic.loadUiType()
引起的吗?
Python(PyQt5)代码:
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys
baseUIClass, baseUIWidget = uic.loadUiType("main_window.ui")
class main_window_logic(baseUIWidget, baseUIClass):
""" Handles Logic for the Main Window (main_window.ui)"""
def __init__(self, parent = None):
super(main_window_logic,self).__init__(parent)
self.setupUi(self)
self.listWidget.setAlternatingRowColors(True)
self.Main_Window.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ui = main_window_logic(None)
ui.show()
sys.exit(app.exec_())
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Main_Window</class>
<widget class="QMainWindow" name="Main_Window">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>930</width>
<height>715</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>930</width>
<height>715</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>4</height>
</size>
</property>
<property name="baseSize">
<size>
<width>4</width>
<height>0</height>
</size>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="windowTitle">
<string>title</string>
</property>
<property name="windowOpacity">
<double>4.000000000000000</double>
</property>
<property name="styleSheet">
<string notr="true">QMainWindow {
background-color: qlineargradient(spread:pad, x1:0.0100548, y1:0.631, x2:0.229627, y2:0.931, stop:0.440607 rgba(97, 35, 86, 255), stop:1 rgba(105, 25, 98, 255));
}
</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>251</width>
<height>661</height>
</rect>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QFrame {
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));
} </string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>251</width>
<height>661</height>
</rect>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QListWidget{
font: 75 11pt "Ubuntu Mono";
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(87, 54, 185, 255), stop:1 rgba(168, 41, 41, 255));
;
alternate-background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(226, 24, 24, 255), stop:0.985377 rgba(207, 112, 0, 255));
}
</string>
</property>
<property name="itemAlignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>930</width>
<height>22</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
谢谢。
Main_Window 是顶层,即 window,在您的情况下是通过 self
:
self.setWindowFlags(
QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint
)