如何找到网站的API进行解析?
Али-Мухаммад Закарьяев's questions
如何在 C# 中创建十进制类型的枚举?我只是想卸载该方法,决定用十进制类型传递变量(我有很多),但结果发现不可能创建一个十进制类型的枚举
有可能这样做吗?
如何防止在文本框中输入字母 Wpf& 这里是文本框本身
<TextBox x:Name="MainTextBox" Grid.Row="0" FontSize="15" FontWeight="Bold" Margin="330,0,0,96" TextAlignment="Left"/>
在互联网上,只有WinForms,如果是WPF,那么就有难以理解的KeyPress或类似的东西。
我正在PyQt6中创建一个应用程序,为了防止窗口大小调整,我使用了该方法setFixedSize
,但现在我需要允许这种更改。
怎么做?
主要.py
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Main Window")
self.setFixedSize(645, 500)
def button(self):
# вот здесь мне надо изменить размер окна но у меня это не получается из-за метода setFixedSize
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
安装任何版本的 Unity 时,我都会收到错误“下载失败:验证失败”。我观看了很多文章和视频,尝试了所有方法,并以管理员身份运行 Unity 存档,下载了它,并更改了安装位置(我遇到了更多错误)在这种情况下我应该做什么?Windows 10 pro(现在是Windows 11 pro)上没有这样的问题
我正在用Python学习MySQL,想在数据库中添加值,但一直出错
_mysql_connector.MySQLInterfaceError: Commands out of sync; you can't run this command now.
我尝试用其他答案解决问题,但他们没有帮助我
这是代码:
import mysql.connector
from mysql.connector import Error
from config import data_base_config
def create_connection_mysql_data_base(
db_host="127.0.0.1",
user_name="root",
user_password="Ali-Muhammad385",
data_base_name=None
):
connection_data_base = None
try:
connection_data_base = mysql.connector.connect(
host=db_host,
user=user_name,
password=user_password,
database=data_base_name
)
print("Data base connection was successfully")
except Error as data_base_connection_error:
print(f"Data base connection was failed {data_base_connection_error}")
return connection_data_base
try:
connection = create_connection_mysql_data_base(
data_base_config["mysql"]["host"],
data_base_config["mysql"]["user"],
data_base_config["mysql"]["password"],
"Application_Users"
)
cursor = connection.cursor()
create_data_base_SQL_query = """
USE Application_Users;
INSERT INTO users
VALUES ("James", "Smith", "1997-10-02", "James89375Smith492",
"mail", "JamesSmith285@gmail.com", "James89375Smith492", 222-457);"""
cursor.execute(create_data_base_SQL_query)
connection.commit()
cursor.close()
connection.close()
except Error as data_base_error:
print(f"Error {data_base_error}")
编辑:我被要求添加错误的全文
Traceback (most recent call last): File "C:\Users\777\OneDrive\Рабочий стол\QuizApp\data_base\main_data_base.py", line 40, in <module> connection.commit() File "C:\Users\777\OneDrive\Рабочий стол\QuizApp\venv\Lib\site-packages\mysql\connector\connection_cext.py", line 511, in commit self._cmysql.commit() _mysql_connector.MySQLInterfaceError: Commands out of sync; you can't run this command now
我正在用PyQt6编写一个程序,那里有很多小部件。但在某些时候,我意识到程序窗口只是停止减小到某个大小以下。
主要.py
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QApplication, QMainWindow
from quiz_application import QuizApplication
from enter_or_register import EnterOrRegister
from login_window import LoginWindow
from logo import LogosForEnterOrRegister
# from login_window import LoginWindow
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 650, 600)
self.centralwidget = QtWidgets.QWidget()
self.centralwidget.setObjectName("centralwidget")
self.setCentralWidget(self.centralwidget)
self.quizApplication = QuizApplication()
self.enterOrRegister = EnterOrRegister()
self.loginwindow = LoginWindow()
self.logosForEnterOrRegister = LogosForEnterOrRegister()
self.stack = QtWidgets.QStackedWidget(self)
self.ix_stack_1 = self.stack.addWidget(self.quizApplication)
self.ix_stack_2 = self.stack.addWidget(self.enterOrRegister)
self.ix_stack_3 = self.stack.addWidget(self.loginwindow)
self.ix_stack_4 = self.stack.addWidget(self.logosForEnterOrRegister)
self.QVBlayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.QVBlayout.addWidget(self.stack)
# buttons clicked connectors
self.quizApplication.start_button.clicked.connect(
self.on_start_button_clicked)
self.enterOrRegister.register_button.clicked.connect(
self.on_register_button_clicked
)
self.enterOrRegister.back_button.clicked.connect(
self.on_back_button_clicked)
# functions
def on_start_button_clicked(self):
self.stack.setCurrentIndex(1)
self.setStyleSheet("""border-image: unset;""")
def on_register_button_clicked(self):
self.stack.setCurrentIndex(2)
self.setStyleSheet("""border-image: unset;""")
def on_enter_button_clicked(self):
pass
# self.stack.setCurrentIndex(3)
# self.setStyleSheet("""border-image: unset;""")
def on_back_button_clicked(self):
self.stack.setCurrentIndex(0)
self.setStyleSheet(
"""
#centralwidget {
border-image: url(images/battle_images/marathon_battle-photo_2.jpg)"\
"0 0 0 0 stretch stretch;
}"""
)
StyleSheet = """
#centralwidget {
border-image: url(images/battle_images/marathon_battle-photo_2.jpg)"\
"0 0 0 0 stretch stretch;
}
#welcome_label {
font-size: 23px;
}
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
#back_button {
font-size: 20px;
background-color: #008000;
}
#select_enter_register {
font-size: 21px;
color: #00FA9A;
}
#instructional_label {
font-size: 20px;
color: rgba(135, 155, 200, 226);
}
#register_label {
font-size: 20px;
color: rgba(35, 255, 121, 226);
}
#enter_button {
font-size: 20px;
background-color: #008000;
color: rgba(255, 255, 0, 226);
}
#register {
font-size: 20px;
background-color: #008000;
color: rgba(255, 255, 0, 226);
}
"""
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
输入或注册.py
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget
# from PyQt6.QtGui import QPixmap
from logo import LogosForEnterOrRegister
class EnterOrRegister(LogosForEnterOrRegister, QWidget):
def __init__(self):
super().__init__()
self.select_enter_register = QtWidgets.QLabel(self)
self.select_enter_register.setObjectName("select_enter_register")
self.select_enter_register.setText("Enter or register")
self.select_enter_register.setWordWrap(False)
self.select_enter_register.setAlignment(
QtCore.Qt.AlignmentFlag.AlignCenter
| QtCore.Qt.AlignmentFlag.AlignVCenter
)
self.select_enter_register.adjustSize()
self.enter_button = QtWidgets.QPushButton(self)
self.enter_button.setObjectName("enter_button")
self.enter_button.setText("Enter")
self.enter_button.setFixedSize(300, 100)
self.register_label = QtWidgets.QLabel(self)
self.register_label.setObjectName("register_label")
self.register_label.setText("Not logged in yet?")
self.register_label.setWordWrap(False)
self.register_label.setAlignment(
QtCore.Qt.AlignmentFlag.AlignCenter
)
self.register_label.adjustSize()
self.register_button = QtWidgets.QPushButton(self)
self.register_button.setObjectName("register")
self.register_button.setText("Register")
self.register_button.adjustSize()
self.back_button = QtWidgets.QPushButton(self)
self.back_button.setObjectName("back_button")
self.back_button.setText("<- Back")
self.back_button.adjustSize()
# layouts
self.QVB_layout = QtWidgets.QVBoxLayout(self)
self.QVB_layout.addWidget(
self.select_enter_register,
alignment=QtCore.Qt.AlignmentFlag.AlignTop)
self.QVB_layout.addWidget(
self.enter_button,
alignment=QtCore.Qt.AlignmentFlag.AlignCenter)
self.QVB_layout.addWidget(
self.register_label,
alignment=QtCore.Qt.AlignmentFlag.AlignCenter)
self.QVB_layout.addWidget(
self.register_button,
alignment=QtCore.Qt.AlignmentFlag.AlignTop
)
self.QVB_layout.addLayout(
self.QHB_logo_layout
)
quiz_application.py
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget
# from PyQt6.QtGui import QPixmap
class QuizApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 645, 500)
self.welcome_label = QtWidgets.QLabel(self)
self.welcome_label.setObjectName("welcome_label")
self.welcome_label.setText("Welcome to Marathon Battle!")
self.welcome_label.setWordWrap(False)
self.welcome_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.start_button = QtWidgets.QPushButton(self)
self.start_button.setObjectName("start_button")
self.start_button.setText("Start Quiz")
self.start_button.adjustSize()
self.quiz_QVBlayout = QtWidgets.QVBoxLayout(self)
self.quiz_QVBlayout.addWidget(
self.welcome_label,
alignment=QtCore.Qt.AlignmentFlag.AlignTop
)
self.quiz_QVBlayout.addWidget(
self.start_button,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
登录窗口.py:
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Login Window")
self.setGeometry(300, 300, 300, 308)
self.setFixedSize(300, 308)
self.instructional_label = QtWidgets.QLabel(self)
self.instructional_label.setObjectName("instructional_label")
self.instructional_label.setText("Enter your login and password")
self.instructional_label.setWordWrap(False)
# self.instructional_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
self.instructional_label.adjustSize()
self.login_label = QtWidgets.QLabel(self)
self.login_label.setObjectName("login_text")
self.login_label.setText("Login")
self.login_label.setWordWrap(False)
# self.login_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.login_label.adjustSize()
self.login_edit_text = QtWidgets.QLineEdit(self)
self.login_edit_text.setObjectName("login_edit_text")
# self.login_edit_text.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.password_edit_text = QtWidgets.QLineEdit(self)
self.password_edit_text.setObjectName("password_edit_text")
# self.password_edit_text.setAlignment(
# QtCore.Qt.AlignmentFlag.AlignCenter)
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.addWidget(
self.instructional_label,
alignment=QtCore.Qt.AlignmentFlag.AlignVCenter)
self.layout.addWidget(
self.login_label,
alignment=QtCore.Qt.AlignmentFlag.AlignVCenter)
self.layout.addWidget(
self.login_edit_text,
alignment=QtCore.Qt.AlignmentFlag.AlignVCenter)
self.layout.addWidget(
self.password_edit_text,
alignment=QtCore.Qt.AlignmentFlag.AlignVCenter)
标志.py:
from PyQt6 import QtWidgets, QtGui, QtCore
from PyQt6.QtWidgets import QWidget
class LogosForEnterOrRegister(QWidget):
def __init__(self):
super().__init__()
self.facebook_logo = QtGui.QPixmap("images/logos/facebook_logo.png")
self.facebook_logo_label = QtWidgets.QLabel(self)
self.facebook_logo_label.setPixmap(self.facebook_logo)
self.facebook_logo_label.adjustSize()
self.git_hub_logo = QtGui.QPixmap("images/logos/GitHub_logo.png")
self.git_hub_logo_label = QtWidgets.QLabel(self)
self.git_hub_logo_label.setPixmap(self.git_hub_logo)
self.git_hub_logo_label.adjustSize()
self.google_logo = QtGui.QPixmap("images/logos/google_logo.png")
self.google_logo_label = QtWidgets.QLabel(self)
self.google_logo_label.setPixmap(self.google_logo)
self.google_logo_label.adjustSize()
self.yandex_logo = QtGui.QPixmap("images/logos/yandex_logo.png")
self.yandex_logo_label = QtWidgets.QLabel(self)
self.yandex_logo_label.setPixmap(self.yandex_logo)
self.yandex_logo_label.adjustSize()
self.meta_logo = QtGui.QPixmap("images/logos/meta_logo.png")
self.meta_logo_label = QtWidgets.QLabel(self)
self.meta_logo_label.setPixmap(self.meta_logo)
self.meta_logo_label.adjustSize()
self.QHB_logo_layout = QtWidgets.QHBoxLayout()
self.QHB_logo_layout.addWidget(
self.facebook_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
self.QHB_logo_layout.addWidget(
self.git_hub_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
self.QHB_logo_layout.addWidget(
self.google_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
self.QHB_logo_layout.addWidget(
self.yandex_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
self.QHB_logo_layout.addWidget(
self.meta_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
以下是应用程序图像:
我正在用 PyQt6 编写一个程序,我需要将它放在QVBoxLayout
一个QHBoxLayout
窗口中,这样QVBoxLayout
它的小部件就有一个主要的小部件,QHBoxLayout
位于QVBoxLayout
.
我尝试过addLayout
,但所有的小部件都混乱了。我希望我解释清楚了。
这是代码(缩写):
主要.py:
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QApplication, QMainWindow
from quiz_application import QuizApplication
from enter_or_register import EnterOrRegister
from login_window import LoginWindow
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 643, 500)
self.centralwidget = QtWidgets.QWidget()
self.centralwidget.setObjectName("centralwidget")
self.setCentralWidget(self.centralwidget)
self.quizApplication = QuizApplication()
self.enterOrRegister = EnterOrRegister()
self.loginwindow = LoginWindow()
self.stack = QtWidgets.QStackedWidget(self)
self.ix_stack_1 = self.stack.addWidget(self.quizApplication)
self.ix_stack_2 = self.stack.addWidget(self.enterOrRegister)
self.ix_stack_3 = self.stack.addWidget(self.loginwindow)
self.QVBlayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.QVBlayout.addWidget(self.stack)
self.quizApplication.start_button.clicked.connect(
self.on_start_button_clicked)
# functions
def on_start_button_clicked(self):
self.stack.setCurrentIndex(1)
self.setStyleSheet("""border-image: unset;""")
StyleSheet = """
#centralwidget {
border-image: url(images/battle_images/marathon_battle-photo_2.jpg)"\
"0 0 0 0 stretch stretch;
}
#welcome_label {
font-size: 23px;
}
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
#select_enter_register {
font-size: 21px;
color: #00FA9A;
}
#instructional_label {
font-size: 20px;
color: rgba(135, 155, 200, 226);
}
#register_label {
font-size: 20px;
color: rgba(35, 255, 121, 226);
}
#enter_button {
font-size: 20px;
background-color: #008000;
color: rgba(255, 255, 0, 226);
}
"""
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
输入或注册.py
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget
from PyQt6.QtGui import QPixmap
class EnterOrRegister(QWidget):
def __init__(self):
super().__init__()
self.select_enter_register = QtWidgets.QLabel(self)
self.select_enter_register.setObjectName("select_enter_register")
self.select_enter_register.setText("Enter or register")
self.select_enter_register.setWordWrap(False)
self.select_enter_register.setAlignment(
QtCore.Qt.AlignmentFlag.AlignCenter
| QtCore.Qt.AlignmentFlag.AlignVCenter
)
self.select_enter_register.adjustSize()
self.enter_button = QtWidgets.QPushButton(self)
self.enter_button.setObjectName("enter_button")
self.enter_button.setText("Enter")
self.enter_button.setFixedSize(300, 100)
self.register_label = QtWidgets.QLabel(self)
self.register_label.setObjectName("register_label")
self.register_label.setText("Not logged in yet?")
self.register_label.setWordWrap(False)
self.register_label.setAlignment(
QtCore.Qt.AlignmentFlag.AlignCenter
)
self.register_label.adjustSize()
self.register_button = QtWidgets.QPushButton(self)
self.register_button.setObjectName("register")
self.register_button.setText("Register")
self.register_button.adjustSize()
self.google_logo = QPixmap("images/logos/google_logo.png")
self.google_logo_label = QtWidgets.QLabel(self)
self.google_logo_label.setPixmap(self.google_logo)
self.google_logo_label.adjustSize()
self.git_hub_logo = QPixmap("images/logos/GitHub_logo.png")
self.git_hub_logo_label = QtWidgets.QLabel(self)
self.git_hub_logo_label.setPixmap(self.git_hub_logo)
self.git_hub_logo_label.adjustSize()
self.QHB_layout = QtWidgets.QHBoxLayout(self)
# вот мне нужно чтобы вот это QHB_layout находился внутри QVB_layout.
self.QVB_layout = QtWidgets.QVBoxLayout(self)
self.QVB_layout.addWidget(
self.select_enter_register,
alignment=QtCore.Qt.AlignmentFlag.AlignTop)
self.QVB_layout.addWidget(
self.enter_button,
alignment=QtCore.Qt.AlignmentFlag.AlignCenter)
self.QVB_layout.addWidget(
self.register_label,
alignment=QtCore.Qt.AlignmentFlag.AlignCenter)
self.QVB_layout.addWidget(
self.register_button,
alignment=QtCore.Qt.AlignmentFlag.AlignTop
)
self.QHB_layout.addWidget(
self.google_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom)
self.QHB_layout.addWidget(
self.git_hub_logo_label,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom)
self.QHB_layout.addLayout(self.QVB_layout)
我正在用 PyQt6 编写一个程序,我需要编写一个按钮的代码。
我正在使用lambda
按钮响应函数。那些。我需要做到这一点,以便当按下按钮时,所有(包括中央小部件)小部件都会被清除,并添加其他小部件。
在我的代码中,仅删除按钮本身和顶部的铭文,而背景保留
简而言之,我需要确保按下按钮时,所有小部件都被清除,包括背景(或者它更改为另一个小部件)并添加其他小部件。
主要.py:
import sys
from PyQt6 import QtWidgets, QtCore
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget
class EnterOrRegister(QWidget):
def __init__(self):
super().__init__()
self.select_enter_register = QtWidgets.QLabel(self)
self.select_enter_register.setObjectName("select_enter_register")
self.select_enter_register.setText("Enter or register")
self.select_enter_register.setWordWrap(False)
self.select_enter_register.setAlignment(
QtCore.Qt.AlignmentFlag.AlignCenter
)
self.select_enter_register.adjustSize()
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.select_enter_register)
class QuizApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 645, 500)
self.welcome_label = QtWidgets.QLabel(self)
self.welcome_label.setObjectName("welcome_label")
self.welcome_label.setText("Welcome to Marathon Battle!")
self.welcome_label.setWordWrap(False)
self.welcome_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.start_button = QtWidgets.QPushButton(self)
self.start_button.setObjectName("start_button")
self.start_button.setText("Start Quiz")
self.start_button.adjustSize()
self.quiz_QVBlayout = QtWidgets.QVBoxLayout(self)
self.quiz_QVBlayout.addWidget(
self.welcome_label,
alignment=QtCore.Qt.AlignmentFlag.AlignTop
)
self.quiz_QVBlayout.addWidget(
self.start_button,
alignment=QtCore.Qt.AlignmentFlag.AlignBottom
)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 645, 500)
self.centralwidget = QtWidgets.QWidget()
self.centralwidget.setObjectName("centralwidget")
self.setCentralWidget(self.centralwidget)
self.quizApplication = QuizApplication()
self.enterOrRegister = EnterOrRegister()
self.stack = QtWidgets.QStackedWidget(self)
self.ix_stack_1 = self.stack.addWidget(self.quizApplication)
ix_stack_2 = self.stack.addWidget(self.enterOrRegister)
self.QVBlayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.QVBlayout.addWidget(self.stack)
self.quizApplication.start_button.clicked.connect(
lambda: self.stack.setCurrentIndex(ix_stack_2)
)
StyleSheet = """
#centralwidget {
border-image: url(images/battle_images/battle-of-marathon-war.jpg)"\
"0 0 0 0 stretch stretch;
}
#welcome_label {
font-size: 23px;
}
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
#select_enter_register {
font-size: 21px;
color: #00FA9A;
background-color: rgba(220, 0, 0, 70);
border: 2px solid #f9009B;
border-radius: 22px;
min-width: 296px;
min-height: 196px;
max-width: 400px;
max-height: 300px;
}
#instructional_label {
font-size: 20px;
color: rgba(135, 155, 200, 226);
}
"""
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
我正在编写一个PyQt6应用程序,我需要将代码分成几个文件。
第一个文件创建主窗口,其中有一个单击按钮,该按钮可清除所有小部件,并且必须添加已经从另一个文件中添加的新小部件。
我尝试导入到主文件中,执行不同的功能,执行lambda
功能,继承类,但没有任何帮助。
这是代码:
主要.py
from PyQt6 import QtWidgets, QtGui, QtCore
from PyQt6.QtWidgets import QApplication, QWidget
import enter_or_register
import sys
class QuizApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 645, 500)
self.layout = QtWidgets.QGridLayout()
self.pixmap = QtGui.QPixmap("marathon_battle-photo.jpg")
self.background_label = QtWidgets.QLabel(self)
self.background_label.setObjectName("background_label")
self.background_label.setPixmap(self.pixmap)
self.background_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.background_label.adjustSize()
self.welcome_label = QtWidgets.QLabel(self)
self.welcome_label.setObjectName("welcome_label")
self.welcome_label.setText("Welcome to Marathon Battle!")
self.welcome_label.setWordWrap(False)
self.welcome_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.start_button = QtWidgets.QPushButton(self)
self.start_button.setObjectName("start_button")
self.start_button.setText("Start Quiz")
self.start_button.clicked.connect(self.on_start_clicked)
# и мне нужно чтобы по нажатию этой кнопки появлялись виджеты из второго файла
self.start_button.adjustSize()
self.layout.addWidget(self.welcome_label)
self.layout.addWidget(self.background_label)
self.layout.addWidget(self.start_button)
self.layout.setSpacing(10)
self.setLayout(self.layout)
def on_start_clicked(self):
self.background_label.clear()
self.welcome_label.clear()
self.start_button.close()
StyleSheet = """
#centralwidget {
border-image: url(background.png) 0 0 0 0 stretch stretch;
}
#welcome_label {
font-size: 23px;
}
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
#instructional_label {
font-size: 20px;
color: rgba(135, 155, 200, 226);
}
"""
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = QuizApplication()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
输入或注册.py
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget
class EnterOrRegister(QWidget):
def __init__(self):
super().__init__()
self.select_enter_register = QtWidgets.QLabel(self)
self.select_enter_register.setObjectName("select_enter_register")
self.select_enter_register.setText("Enter or register")
self.select_enter_register.setWordWrap(False)
self.select_enter_register.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.select_enter_register.adjustSize()
我正在PyQt6中制作一个多窗口应用程序,我想StyleSheet
向第二个窗口添加一个方法,但我不知道该怎么做(我正在写哎呀)。
主要.py:
from PyQt6 import QtWidgets
import sys
class QuizApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz Application")
self.setGeometry(300, 50, 645, 500)
self.layout = QtWidgets.QGridLayout()
self.start_button = QtWidgets.QPushButton(self)
self.start_button.setObjectName("start_button")
self.start_button.setText("Start Quiz")
self.start_button.clicked.connect(self.on_start_clicked)
self.start_button.adjustSize()
self.layout.addWidget(self.welcome_label)
self.layout.addWidget(self.background_label)
self.layout.addWidget(self.start_button)
self.layout.setSpacing(10)
self.setLayout(self.layout)
def on_start_clicked(self):
self.login_window = LoginWindow()
self.login_window.show()
StyleSheet = """
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
"""
def application_setup():
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = QuizApplication()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
application_setup()
window_2.py:
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtWidgets import QWidget, QGridLayout
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Login Window")
self.setGeometry(300, 300, 300, 300)
self.instructional_label = QtWidgets.QLabel(self) # и как добавить Stylesheet к этой надписи???
self.instructional_label.setObjectName("instructional_label")
self.instructional_label.setText("Please enter your login and password")
self.instructional_label.setWordWrap(False)
self.instructional_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
self.layout = QGridLayout(self)
self.layout.addWidget(self.instructional_label)
self.setLayout(self.layout)
我尝试在第一个文件中添加样式表,但没有任何效果
我在 PyQt5 中编写了一个应用程序,但后来我决定迁移到 PyQt6。我开始遇到错误,例如 PyQt6 没有我在 PyQt5 中使用的模块。我查阅了文档,解决了几个问题,但无法解决最后一个问题,即我将一个铭文放置在 QGridLayout 中并使用该方法将其固定在窗口的中心,但是在更新到 PyQt6setAlignment(Qt.AlignCenter)
之后,我发现新版本中的Qt模块没有。我去搜索文档、互联网、YouTube、stackoverflow 以及任何可能的地方,并在文档中发现您应该使用 pyqtProperty,而不是 Qt 模块。我去将它导入到一个文件中,但它甚至没有为我导入!到底要做什么以及如何使用这个 pyqtProperty?这是代码:
from PyQt6.QtWidgets import QApplication, QLabel, \
QPushButton, QGridLayout, QWidget
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import pyqtProperty # вот это атрибут(метод) я хотел импортировать, но у меня не получилось
import sys
class QuizApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Quiz")
self.setGeometry(600, 100, 648, 500)
self.pixmap = QPixmap("background_image.jpg")
self.background_label = QLabel(self)
self.background_label.setObjectName("background_label")
# self.background_label.setAlignment(Qt.AlignCenter) вот это метод я использовал в PyQt5
self.background_label.pyqtProperty()
self.background_label.setPixmap(self.pixmap)
self.background_label.adjustSize()
self.welcome_label = QLabel(self)
self.welcome_label.move(200, 0)
self.welcome_label.setObjectName("welcome_label")
# self.welcome_label.setAlignment(Qt.AlignCenter)
self.welcome_label.setWordWrap(False)
self.welcome_label.setText(
"Это будет викторина по истории, философии и обществознанию.")
self.welcome_label.adjustSize()
self.start_button = QPushButton(self)
self.start_button.move(100, 480)
self.start_button.setObjectName("start_button")
self.start_button.setText("Нажмите чтобы начать!")
self.start_button.adjustSize()
self.grid = QGridLayout()
self.grid.addWidget(self.welcome_label)
self.grid.addWidget(self.background_label)
self.grid.addWidget(self.start_button)
self.grid.setSpacing(10)
self.setLayout(self.grid)
StyleSheet = """
#centralwidget {
border-image: url(background.png) 0 0 0 0 stretch stretch;
}
#welcome_label {
font-size: 23px;
}
#start_button {
font-size: 20px;
color: #ADFF2F;
background-color: #008000;
}
"""
# color: #f77;
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
window = QuizApplication()
window.resize(648, 500)
window.show()
sys.exit(app.exec())
我正在PyQt5中制作测验应用程序。我添加了文本、按钮和背景图像,但下一个问题是如何使窗口响应?
我在 RuNet、英语互联网和 YouTube 上进行了很多谷歌搜索,但我没有找到任何东西。
主要.py:
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QPixmap
import sys
class QuizApplication(QMainWindow):
def __init__(self):
super(QuizApplication, self).__init__()
self.setWindowTitle("Quiz")
self.setGeometry(600, 100, 648, 500)
self.pixmap = QPixmap("background_image.jpg")
self.background_label = QtWidgets.QLabel(self)
self.background_label.setPixmap(self.pixmap)
self.background_label.adjustSize()
self.welcome_label = QtWidgets.QLabel(self)
self.welcome_label.move(100, 0)
self.welcome_label.setText("Это будет викторина по истории, философии и обществознанию")
self.welcome_label.adjustSize()
self.start_button = QtWidgets.QPushButton(self)
self.start_button.move(220, 20)
self.start_button.setText("Нажмите чтобы начать!")
self.start_button.adjustSize()
def aplication_setup():
app = QApplication(sys.argv)
window = QuizApplication()
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
aplication_setup()
我开始学习PyQt5,但是我无法制作主窗口。这是代码:
import sys
from PyQt5.QtWidgets import QApplication, QWidget
class App_PyQt(QApplication):
def __init__(self):
self.app = QApplication(sys.argv())
self.w = QWidget()
self.w.resize(300, 300)
self.w.move(300, 500)
self.w.setWindowTitle("Example")
self.w.show()
sys.exit(self.app.exec_())
Main_Window = App_PyQt()