我遇到了这样一个问题:我用PyQt5写了一个程序,它运行良好,我在pyinstaller的帮助下制作了一个.exe文件,因为我会经常使用它,当我运行可执行文件时,除了它,控制台打开。是否有可能以某种方式阻止控制台的打开?
先感谢您
我遇到了这样一个问题:我用PyQt5写了一个程序,它运行良好,我在pyinstaller的帮助下制作了一个.exe文件,因为我会经常使用它,当我运行可执行文件时,除了它,控制台打开。是否有可能以某种方式阻止控制台的打开?
先感谢您
面临这样一个问题:是否有可能以某种方式转换以下代码使用string
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str[3] = { "Anna", "Max", "Dan" };
for (int i = 0; i < strlen(str); i++) {
cout << str[i] << " ";
}
}
编码使用char?我知道是什么char将单词分成字符,所以我不确定这是否可能。请帮我弄清楚!
任务设置如下:你需要在一个棋场上放置8个皇后,这样它们就不会受到对方的攻击。
我在 C++ 中实现了这个任务,如下所示:
#include <iostream>
using namespace std;
int main() {
setlocale(LC_ALL, "ru");
int q[8], c, i;
int count = 1;
q[0] = 0;
c = 0;
NC:
c++;
if (c == 8) goto print;
q[c] = -1;
NR:
q[c]++;
if (q[c] == 8) goto back;
for (i = 0; i < c; i++) {
if ((q[i] == q[c]) || ((c - i) == abs(q[c] - q[i]))) goto NR;
}
goto NC;
back:
c--;
if (c == -1) return 0;
goto NR;
print:
cout << "---------------------------------";
cout << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (j == q[i]) {
cout << "| Ф ";
}
else {
cout << "| ";
}
}
cout << "|";
cout << endl;
cout << "---------------------------------";
cout << endl;
}
system("pause");
return 0;
}
告诉我如何修复我的代码以便我不使用goto?我将不胜感激。
如何在 Python 中找到 .txt 类型的文件,同时文件的名称以“result”开头。也就是说,在我的文件夹中的文件是:result_275.txt, result_351.txt,task.txt
程序如何找到这些文件并例如显示它们的名称?
单击按钮时是否可以执行两个功能?我请求你的帮助!
这是我的窗口类:
class Window_3(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_regit()
self.ui.setupUi(self)
self.ui.pushButton3.clicked.connect(self.go_end)
self.ui.pushButton4.clicked.connect(self.processor) # хочу вызвать processor и matherboard
def go_end(self):
self.hide()
def processor(self):
name_proc = "ProcessorNameString"
n_p = True
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0") as sub_key:
try:
i = 0
while n_p:
path_value = winreg.EnumValue(sub_key, i)
if name_proc == path_value[0]:
self.ui.label_proc_info.setText(f"{path_value[1]}")
print(f"Proseccor: {path_value[1]}")
n_p = False
else:
i += 1
except OSError:
print("processor not found")
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
def matherboard(self):
name_proc = "BaseBoardproduct"
n_p = True
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "HARDWARE\\DESCRIPTION\\System\\BIOS\\0") as sub_key:
try:
i = 0
while n_p:
path_value = winreg.EnumValue(sub_key, i)
if name_proc == path_value[0]:
self.ui.label_proc_info_2.setText(f"{path_value[1]}")
n_p = False
else:
i += 1
except OSError:
pass
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
我能够实现太平庸的代码,以便将数组循环移动一个值。您需要以某种方式通过 k 值实现移位,并且您不能使用任何函数,只能使用循环。我请求你的帮助!
我的代码:
#include <iostream>
using namespace std;
int main()
{
const int N = 4;
int arr[N] = { 1, 2, 3, 4 };
int el = arr[0];
for (int i = 1; i < N; ++i)
arr[i - 1] = arr[i];
arr[N - 1] = el;
for (int i = 0; i < N; ++i)
cout << arr[i] << " ";
}
我最近开始学习 C++,我的代码很蹩脚。您需要输出以下内容:
我怎样才能缩短我的代码(我相信你可以)?
#include <iostream>
#include <string>
using namespace std;
int main() {
setlocale(LC_ALL, "ru");
string simvol = "*";
int control = 7;
for (int j = 0; j < control; j++) {
cout << simvol << " ";
}
cout << endl;
for (int j = 0; j < control; j++) {
if ((j == 0) || (j == control - 1)) {
cout << " ";
}
else {
cout << simvol << " ";
}
}
cout << endl;
for (int j = 0; j < control; j++) {
if ((j == 0) || (j == 1) || (j == control - 1) || (j == control - 2)) {
cout << " ";
}
else {
cout << simvol << " ";
}
}
cout << endl;
for (int j = 0; j < control; j++) {
if ((j == 0) || (j == 1) || (j == 2) || (j == control - 1) || (j == control - 2) || (j == control - 3)) {
cout << " ";
}
else {
cout << simvol << " ";
}
}
cout << endl;
for (int j = 0; j < control; j++) {
if ((j == 0) || (j == 1) || (j == control - 1) || (j == control - 2)) {
cout << " ";
}
else {
cout << simvol << " ";
}
}
cout << endl;
for (int j = 0; j < control; j++) {
if ((j == 0) || (j == control - 1)) {
cout << " ";
}
else {
cout << simvol << " ";
}
}
cout << endl;
for (int j = 0; j < control; j++) {
cout << simvol << " ";
}
}
如何跟踪应用程序的打开副本并关闭主要副本?
我读到互斥量和信号量用于此目的,但我不知道如何将其与PyQt5连接起来。
例如,我启动一个应用程序,启动它后,我再次打开它。例如,我如何警告应用程序已经在运行?
我希望能得到你的帮助。
以下情况:我需要以某种方式,使用注册表,在5工作几分钟后关闭程序并要求,例如,购买主要订阅。
我所做的最多是在一定数量的启动后实施关闭。
import winreg
import sys
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow
number, start_program = "", True
def software():
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "SOFTWARE") as sub_key:
try:
i = 0
while True:
path_value = winreg.EnumKey(sub_key, i)
print(f"{path_value}")
i += 1
except OSError:
print()
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
def read_key_software():
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run") as sub_key:
try:
i = 0
while True:
path_value = winreg.EnumValue(sub_key, i)
print(f"{path_value}")
i += 1
except OSError:
print("")
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
def matherboard():
name_board = "BaseBoardProduct"
n_b = True
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "HARDWARE\\DESCRIPTION\\System\\BIOS") as sub_key:
try:
i = 0
while n_b:
path_value = winreg.EnumValue(sub_key, i)
if name_board == path_value[0]:
print(f"Matherboard: {path_value[1]}")
n_b = False
else:
i += 1
except OSError:
print("matherboard not found")
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
print("")
def processor():
name_proc = "ProcessorNameString"
n_p = True
with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as hkey:
with winreg.OpenKey(hkey, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0") as sub_key:
try:
i = 0
while n_p:
path_value = winreg.EnumValue(sub_key, i)
if name_proc == path_value[0]:
print(f"Proseccor: {path_value[1]}")
n_p = False
else:
i += 1
except OSError:
print("processor not found")
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
print("")
def SPLab():
global number, start_program
path = False
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as hkey:
with winreg.OpenKey(hkey, "SOFTWARE") as sub_key:
winreg.CreateKey(sub_key, "SPLab")
winreg.CloseKey(hkey)
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as hkey:
with winreg.OpenKey(hkey, "SOFTWARE\\SPLab", 0, winreg.KEY_READ) as sub_key:
try:
num = winreg.EnumValue(sub_key, 0)
path = True
start = num[1]
if int(start) >= 10:
start_program = False
except OSError:
path = False
winreg.CloseKey(sub_key)
with winreg.OpenKey(hkey, "SOFTWARE\\SPLab", 0, winreg.KEY_WRITE) as sub_key:
if path:
start = int(start) + 1
else:
start = "1"
winreg.SetValueEx(sub_key, "NamberOfStarts", 0, winreg.REG_SZ, str(start))
winreg.CloseKey(sub_key)
winreg.CloseKey(hkey)
number = start
print("")
class mainWin(QMainWindow):
def __init__(self):
super(mainWin, self).__init__()
self.setWindowTitle("Program")
if start_program:
self.setGeometry(1000, 300, 580, 270)
self.setStyleSheet("background : lightyellow;")
self.b1 = QtWidgets.QPushButton(self)
self.b1.setGeometry(20, 20, 250, 70)
self.b1.setStyleSheet("background : lightgreen; font-size : 20px")
self.b1.setText("software")
self.b1.clicked.connect(software)
self.b2 = QtWidgets.QPushButton(self)
self.b2.setGeometry(300, 20, 250, 70)
self.b2.setStyleSheet("background : lightgreen; font-size : 20px")
self.b2.setText("read_key_software")
self.b2.clicked.connect(read_key_software)
self.b3 = QtWidgets.QPushButton(self)
self.b3.setGeometry(20, 120, 250, 70)
self.b3.setStyleSheet("background : lightgreen; font-size : 20px")
self.b3.setText("matherboard")
self.b3.clicked.connect(matherboard)
self.b4 = QtWidgets.QPushButton(self)
self.b4.setGeometry(300, 120, 250, 70)
self.b4.setStyleSheet("background : lightgreen; font-size : 20px")
self.b4.setText("processor")
self.b4.clicked.connect(processor)
self.l5 = QtWidgets.QLabel(self)
self.l5.setGeometry(20, 210, 250, 50)
self.l5.setText(f"Number of starts: {number}")
self.l5.setStyleSheet("font-size : 20px")
else:
self.setGeometry(800, 400, 850, 300)
self.setStyleSheet("background : white;")
self.l1 = QtWidgets.QLabel(self)
self.l1.setGeometry(25, 100, 1000, 70)
self.l1.setText("Buy the full version of the program!")
self.l1.setStyleSheet("font-size : 50px")
if __name__ == "__main__":
SPLab()
app = QApplication(sys.argv)
mwin = mainWin()
mwin.show()
print("")
sys.exit(app.exec_())