我正在尝试为我正在使用 python 3.3.4 和 PyQt4 编写的 GUI 应用程序获取旋转日志文件。
我的主脚本中有以下代码片段:
import logging
import resources
logger = logging.getLogger('main.test')
def main():
logger.setLevel(logging.DEBUG)
fh = RotatingFileHandler(resources.LOG_FILE_PATH, maxBytes=500, backupCount=5)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.info('main')
Run Code Online (Sandbox Code Playgroud)
我的 maxBytes 很低,以便我可以测试旋转是否正常工作,但事实并非如此。每当应该轮换日志时,我都会收到以下错误:
Traceback (most recent call last):
File "C:\Python33\lib\logging\handlers.py", line 73, in emit
self.doRollover()
File "C:\Python33\lib\logging\handlers.py", line 176, in doRollover
self.rotate(self.baseFilename, dfn)
File "C:\Python33\lib\logging\handlers.py", line 116, in rotate
os.rename(source, dest)
PermissionError: [WinError 32] The process cannot access the file because it is being …Run Code Online (Sandbox Code Playgroud) 例如,请考虑以下代码:
Rectangle {
id: idRectParent
Rectangle {
id: idRectChild1
component.onCompleted: {
console.log("Iam Child 1")
}
}
Rectangle {
id: idRectChild2
component.onCompleted: {
console.log("Iam Child 2")
}
}
component.onCompleted : {
console.log("Iam parent Rect")
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行它,qmlscene我会得到下面的输出(我已经尝试了近50次).
Iam parent Rect
Iam Child 2
Iam Child 1
Run Code Online (Sandbox Code Playgroud)
为什么输出按上述顺序排列,而不是:
Iam parent Rect
Iam Child 1
Iam Child 2
Run Code Online (Sandbox Code Playgroud)
要么
Iam Child 1
Iam Child 2
Iam parent Rect
Run Code Online (Sandbox Code Playgroud)
或任何其他组合.
我怎样才能创建一个QListWidgetItem,它下面有1个图像和2个标签/字符串,它们支持css?
这是我尝试过的最后一件事:
class CustomListWidgetItem(QListWidgetItem, QLabel):
def __init__(self, parent=None):
QListWidgetItem.__init__(self, parent)
QLabel.__init__(self, parent)
Run Code Online (Sandbox Code Playgroud)
我正在使用PyQt btw
我QPushButton在Qt Designer中创建了这个样式表:
QPushButton#pushButton {
background-color: #ffffff;
}
QPushButton#pushButton:disabled {
background-color: yellow;
}
QPushButton#pushButton:pressed {
background-color: orange;
}
QPushButton#pushButton:focus:pressed {
background-color: black;
}
QPushButton#pushButton:focus {
background-color: green;
}
QPushButton#pushButton:hover {
background-color: red;
}
QPushButton#pushButton:checked {
background-color: pink;
}
Run Code Online (Sandbox Code Playgroud)
它工作,但当我在属性中检查"平",然后它不再工作,我想问你为什么?我怎么能这样做,如果我需要平板QPushButton?
我想知道是否有办法实现系统托盘图标+菜单功能没有小部件模块?
这是我的设置:
一个持续运行并完成其工作的后台进程。
启动上述进程并监视它的启动器,如果崩溃或终止则重新启动它。
我希望添加对启动程序进程的系统托盘访问权限(理想情况下,启动程序进程将包含系统托盘显示的代码),并启用从系统托盘上下文菜单触发基本选项(启动、停止等)。系统托盘不需要自己的窗口。只是一个无窗口系统托盘,带有包含 2-3 个选项的上下文菜单。
由于到目前为止编写的所有代码都是用 C/C++ 编写的,并且我需要它在 Windows 和 Linux 上运行,因此 QT 是显而易见的选择。我发现通过基本的 QT 启动器托盘显示非常令人沮丧。我见过的几乎每个示例都QSystemTrayIcon包含“主窗口”继承。
下面是我用来创建系统托盘的代码。
#include <QtWidgets/QApplication>
#include <QtCore/QDebug>
#include <QtGui/QIcon>
#include <QtWidgets/QSystemTrayIcon>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenu>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPixmap oPixmap(32,32);
//QMenu* menu1 = new QMenu(); // want to get a context menu from system tray
oPixmap.load ("systemTrayIcon.png");
QIcon oIcon( oPixmap );
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(oIcon);
qDebug() << trayIcon->isSystemTrayAvailable();
trayIcon->setContextMenu( menu1);
trayIcon->setVisible(true);
trayIcon->showMessage("Test Message", "Text", …Run Code Online (Sandbox Code Playgroud) 我正在使用给定的代码,我希望用户在 QLineEdit 小部件中输入文本,按复制!按钮并查看输入的文本替换“N/A”标签。我的问题是:按照此过程,如何通过简单的鼠标单击清除 QLineEdit 小部件中输入的文本?
从我读到的(this、this和this)来看,我似乎需要在扩展 QLineEdit 的新类中重新实现 focusInEvent()。我的问题是我的 GUI 代码是使用 pyuic5 从 Qt Designer 导入的,上面引用的示例似乎没有考虑到这一点。
这是我的代码:
from PyQt5.QtWidgets import *
import sys
import QLineEdit_test
class MainWindow(QMainWindow, QLineEdit_test.Ui_QLineEdit_test):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.copy_button.clicked.connect(self.copy_and_print)
def copy_and_print(self):
self.label.setText(self.lineEdit.text())
def main():
app = QApplication(sys.argv)
form = MainWindow()
form.show()
app.exec_()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
这是我转换后的 .ui 文件:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_QLineEdit_test(object):
def setupUi(self, QLineEdit_test):
QLineEdit_test.setObjectName("QLineEdit_test")
QLineEdit_test.resize(300, 200)
QLineEdit_test.setMaximumSize(QtCore.QSize(300, 200))
self.centralwidget = …Run Code Online (Sandbox Code Playgroud) I\xc2\xb4m 尝试对网站进行多处理抓取,在其中我获取要从中获取信息的所有节点的列表,然后生成一个池,这样它就不会并行地逐一获取数据。我的代码如下:
\n\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\nimport multiprocessing\n\ndef ResPartido(node):\n\n ft=node.find_element_by_css_selector(\'.status\').text\n if ft.strip()!=\'FT\': return\n hora=node.find_element_by_css_selector(\'.time\').text\n names=list()\n for nam in node.find_elements_by_xpath(\n \'.//td[contains(@style,"text-align")]/a[contains(@id,"team")]\'):\n name=nam.text\n if \'(N)\' in name:\n name=name.split(\'(N)\')[0]\n names.append(name)\n score=node.find_element_by_css_selector(\'.red\')\n\n return [hora,name,score.text]\n\nif __name__ == "__main__":\n\n browser=webdriver.Chrome()\n SOME CODE\n nodes=browser.find_elements_by_xpath(\n \'//tr[contains(@align,"center")]/following-sibling::tr[.//div[contains(@class,"toolimg")]]\')\n p = multiprocessing.Pool()\n\n p.map(ResPartido,nodes) <---Here is the error\n .......\n\n >>AttributeError: Can\'t pickle local object \'_createenviron.<locals>.encodekey\'\nRun Code Online (Sandbox Code Playgroud)\n\n我的 python 终端出现错误的图像
\n\n
检查文档,它说列表是可选择的对象,并且在主函数之前声明的函数也是如此,所以我不\xc2\xb4t明白使用多处理时我做错了什么。
\n我正在尝试在 Pycharm 中运行此代码,但出现以下错误:
TypeError: expected str, bytes or os.PathLike object, not NoneType
Run Code Online (Sandbox Code Playgroud)
这适用于 Windows 10,在 Pycharm 上运行,python 3.7
import os
import time
file_path = os.path.join(os.getenv("HOME"), "birth_day_lookup.txt")
def check_birthday():
lookup_file = open(file_path, 'r')
today = time.strftime('%d-%B')
flag = 0
for entry in lookup_file:
if today in entry:
line = entry.split(' ')
flag = 1
os.system('notify-send "Today is '+line[1]+' '+line[2]+'\'s Birthday"')
if flag == 0:
os.system('notify-send "No birthday for today is listed"')
check_birthday()
Run Code Online (Sandbox Code Playgroud) 所以我的环境是:
我得到以下信息(在 shell 中):
(base) C:\Users\bbate>activate keras-gpu
(keras-gpu) C:\Users\bbate>spyder
Attribute Qt::AA_UseSoftwareOpenGL must be set before QCoreApplication is created.
[968:13624:1108/111945.157:ERROR:permission_manager_qt.cpp(82)] NOT IMPLEMENTEDUnsupported permission type: 13
Run Code Online (Sandbox Code Playgroud)
然而,Spyder4 启动并工作,但它时不时地挂起,我看到其他注释表明它与 qt dll 有关,但我不知道如何解决这个问题
我看过各种帖子,但没有解决这个错误
顺便说一句,这是一个“干净”的安装;驱动器刚刚重建,所有东西都是全新安装的,所以周围没有太多杂乱,其他版本等。
python ×6
qt ×4
python-3.x ×3
pyqt ×2
qml ×2
qt5 ×2
c++ ×1
flat ×1
logging ×1
miniconda ×1
pickle ×1
pyqt5 ×1
qpushbutton ×1
qt-designer ×1
qtquick2 ×1
spyder ×1
system-tray ×1