Answer the question
In order to leave comments, you need to log in
How to save the written text in QLineEdit when exiting the application?
I made a macro that prints the text written in QLineEdit, but when you restart the application, you have to enter the text again, which is not convenient, and I can’t figure out how to make the text stay in QLineEdit when you restart
. Here is a simplified version of my code
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
import time
import keyboard
import pyautogui
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_ChatSpamer(object):
def __init__(self):
super(Ui_ChatSpamer, self).__init__()
def setupUi(self, ChatSpamer):
ChatSpamer.setObjectName("ChatSpamer")
ChatSpamer.setEnabled(True)
ChatSpamer.resize(500, 430)
ChatSpamer.setMinimumSize(QtCore.QSize(500, 430))
ChatSpamer.setMaximumSize(QtCore.QSize(500, 430))
font = QtGui.QFont()
font.setBold(False)
font.setWeight(50)
ChatSpamer.setFont(font)
ChatSpamer.setStyleSheet("")
self.centralwidget = QtWidgets.QWidget(ChatSpamer)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(30, 70, 291, 20))
self.lineEdit.setTabletTracking(False)
self.lineEdit.setObjectName("lineEdit")
def spammer(self):
if keyboard.is_pressed('f7'):
keyboard.send('t')
time.sleep(0.6)
keyboard.write(self.lineEdit.text(), delay=0.02)
time.sleep(0.6)
keyboard.send('Enter')
time.sleep(6)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ChatSpamer = QtWidgets.QMainWindow()
ui = Ui_ChatSpamer()
ui.setupUi(ChatSpamer)
ChatSpamer.show()
run_inf = QTimer()
run_inf.setInterval(0)
run_inf.timeout.connect(ui.spammer)
run_inf.start()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
https://docs.python.org/3/library/configparser.html
and if the text does not change, you can immediately fill in the form
Ultra-Bad Coder Not working, and most likely there is an error due to the last line of ui.save () as it is highlighted in yellow
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question