Форум сайта python.su
Добрый день, ребят подскажите пожалуйста, найти нигде не могу. Как создать кнопки имитация Backspace и Delete чтоб они работали в поле TextEdit. Суть в чем, есть форма, на ней расположена клавиатура и textedit. С этой виртуальной клавиатуры вводим текст, и надо сделать кнопки Backspace и Delete , но что то ни как не получается реализовать . помогите с кодом
Офлайн
В чем блять кнопки то делать?
Может вы потрудитесь задават свои вопросы более развернуто?
И при чем тут про удалить симво в названии темы?
Офлайн
определить положение курсора в тексте
get текст
в зависимости от del or back button модифицировать текст
переписать текст на элементе
зы не нужно не чего эмулировать
Отредактировано AD0DE412 (Ноя. 15, 2022 20:04:07)
Офлайн
ZerGсоздать кнопку на форме которая будет выполнять действия в поле TextEdit , как кнопки на клавиатуре del и backspace.
В чем блять кнопки то делать? Может вы потрудитесь задават свои вопросы более развернуто?И при чем тут про удалить симво в названии темы?
Офлайн
AD0DE412А можно пример рабочего кода для большего понимания )
определить положение курсора в текстеget текств зависимости от del or back button модифицировать текстпереписать текст на элементезы не нужно не чего эмулировать
Офлайн
НА КАКОЙ ФОРМЕ?
Форме пионера? Форме стиральной машины?
Форме Django, falsk, tkinter,QT, TelegramBot или в чем?
Офлайн
ZerGЯ прикрепил рабочий фаил который делаю, он думаю прояснит ситуацию ))) там только кнопки не добавлены еще 2 штуки которые хочу . del b backspace
НА КАКОЙ ФОРМЕ?Форме пионера? Форме стиральной машины?Форме Django, falsk, tkinter,QT, TelegramBot или в чем?
Прикреплённый файлы:
dz3.py (28,3 KБ)
Офлайн
da_zanyti_vse_imena…
Я прикрепил рабочий фаил который делаю, он думаю прояснит ситуацию
ты просишь помочь но делаешь это без уважения (с)
Отредактировано AD0DE412 (Ноя. 18, 2022 10:18:49)
Офлайн
AD0DE412День добрый, только учусь извиняюсь )). Что не так оформил , ну вопрос остался тем же , помогите пожалуйста кто может. если что то не так скажите исправлю.
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'ui4.ui' # # Created by: PyQt5 UI code generator 5.15.7 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.showFullScreen() MainWindow.setStyleSheet("QMainWindow > QWidget {\n" " background-image: url(D:/python_programm/1/cartitle.png);\n" "}\n" "\n" "QMainWindow {\n" " \n" " background-color: rgb(231, 231, 0);\n" " \n" "}\n" "QPushButton {\n" " border-radius: 10px;\n" " border: 1px solid black;\n" " background-color: rgb(231, 231, 231);\n" " color: rgb(0, 0, 0);\n" " font-size: 33px;\n" " }\n" "QPushButton:pressed {\n" " background-color: rgb(118, 118, 118);\n" " }") self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.textEdit = QtWidgets.QTextEdit(self.centralwidget) self.textEdit.setGeometry(QtCore.QRect(40, 20, 1850, 441)) font = QtGui.QFont() font.setPointSize(18) self.textEdit.setFont(font) self.textEdit.setStyleSheet("") self.textEdit.setMarkdown("") self.textEdit.setObjectName("textEdit") self.gridFrame = QtWidgets.QFrame(self.centralwidget) self.gridFrame.setGeometry(QtCore.QRect(400, 459, 1195, 351)) self.gridFrame.setObjectName("gridFrame") self.gridLayout = QtWidgets.QGridLayout(self.gridFrame) self.gridLayout.setObjectName("gridLayout") self.pushButton_38 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_38.setFont(font) self.pushButton_38.setObjectName("pushButton_38") self.gridLayout.addWidget(self.pushButton_38, 0, 1, 1, 1) self.pushButton_16 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_16.setFont(font) self.pushButton_16.setObjectName("pushButton_16") self.gridLayout.addWidget(self.pushButton_16, 2, 5, 1, 1) self.pushButton_6 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_6.setFont(font) self.pushButton_6.setObjectName("pushButton_6") self.gridLayout.addWidget(self.pushButton_6, 1, 5, 1, 1) self.pushButton_31 = QtWidgets.QPushButton(self.gridFrame) self.pushButton_31.setText(" ") self.pushButton_31.setObjectName("pushButton_31") self.gridLayout.addWidget(self.pushButton_31, 4, 1, 1, 9) self.pushButton_36 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_36.setFont(font) self.pushButton_36.setObjectName("pushButton_36") self.gridLayout.addWidget(self.pushButton_36, 2, 11, 1, 1) self.pushButton_45 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_45.setFont(font) self.pushButton_45.setObjectName("pushButton_45") self.gridLayout.addWidget(self.pushButton_45, 0, 8, 1, 1) self.pushButton_29 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_29.setFont(font) self.pushButton_29.setObjectName("pushButton_29") self.gridLayout.addWidget(self.pushButton_29, 3, 8, 1, 1) self.pushButton_5 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_5.setFont(font) self.pushButton_5.setObjectName("pushButton_5") self.gridLayout.addWidget(self.pushButton_5, 1, 4, 1, 1) self.pushButton_28 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_28.setFont(font) self.pushButton_28.setObjectName("pushButton_28") self.gridLayout.addWidget(self.pushButton_28, 3, 7, 1, 1) self.pushButton_17 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_17.setFont(font) self.pushButton_17.setObjectName("pushButton_17") self.gridLayout.addWidget(self.pushButton_17, 2, 6, 1, 1) self.pushButton_44 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_44.setFont(font) self.pushButton_44.setObjectName("pushButton_44") self.gridLayout.addWidget(self.pushButton_44, 0, 7, 1, 1) self.pushButton_15 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_15.setFont(font) self.pushButton_15.setObjectName("pushButton_15") self.gridLayout.addWidget(self.pushButton_15, 2, 4, 1, 1) self.pushButton_22 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_22.setFont(font) self.pushButton_22.setObjectName("pushButton_22") self.gridLayout.addWidget(self.pushButton_22, 3, 1, 1, 1) self.pushButton_39 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_39.setFont(font) self.pushButton_39.setObjectName("pushButton_39") self.gridLayout.addWidget(self.pushButton_39, 0, 2, 1, 1) self.pushButton_43 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_43.setFont(font) self.pushButton_43.setObjectName("pushButton_43") self.gridLayout.addWidget(self.pushButton_43, 0, 6, 1, 1) self.pushButton_18 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_18.setFont(font) self.pushButton_18.setObjectName("pushButton_18") self.gridLayout.addWidget(self.pushButton_18, 2, 7, 1, 1) self.pushButton_32 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_32.setFont(font) self.pushButton_32.setObjectName("pushButton_32") self.gridLayout.addWidget(self.pushButton_32, 1, 10, 1, 1) self.pushButton_34 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_34.setFont(font) self.pushButton_34.setObjectName("pushButton_34") self.gridLayout.addWidget(self.pushButton_34, 2, 10, 1, 1) self.pushButton_24 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_24.setFont(font) self.pushButton_24.setObjectName("pushButton_24") self.gridLayout.addWidget(self.pushButton_24, 3, 3, 1, 1) self.pushButton_14 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_14.setFont(font) self.pushButton_14.setObjectName("pushButton_14") self.gridLayout.addWidget(self.pushButton_14, 2, 3, 1, 1) self.pushButton_40 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_40.setFont(font) self.pushButton_40.setObjectName("pushButton_40") self.gridLayout.addWidget(self.pushButton_40, 0, 3, 1, 1) self.pushButton_47 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_47.setFont(font) self.pushButton_47.setObjectName("pushButton_47") self.gridLayout.addWidget(self.pushButton_47, 0, 10, 1, 1) self.pushButton_42 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_42.setFont(font) self.pushButton_42.setObjectName("pushButton_42") self.gridLayout.addWidget(self.pushButton_42, 0, 5, 1, 1) self.pushButton_46 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_46.setFont(font) self.pushButton_46.setObjectName("pushButton_46") self.gridLayout.addWidget(self.pushButton_46, 0, 9, 1, 1) self.pushButton_35 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_35.setFont(font) self.pushButton_35.setObjectName("pushButton_35") self.gridLayout.addWidget(self.pushButton_35, 3, 10, 1, 1) self.pushButton_37 = QtWidgets.QPushButton(self.gridFrame) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.pushButton_37.sizePolicy().hasHeightForWidth()) self.pushButton_37.setSizePolicy(sizePolicy) font = QtGui.QFont() font.setPointSize(15) font.setBold(False) font.setWeight(50) font.setKerning(True) self.pushButton_37.setFont(font) self.pushButton_37.setMouseTracking(False) self.pushButton_37.setTabletTracking(False) self.pushButton_37.setStyleSheet("QPushButton {\n" " border-radius: 10px;\n" " border: 1px solid black;\n" " background-color: rgb(231, 231, 231);\n" " color: rgb(0, 0, 0);\n" " font-size: 33px;\n" "}\n" "\n" "QPushButton:pressed {\n" " background-color: rgb(118, 118, 118);\n" "}") self.pushButton_37.setIconSize(QtCore.QSize(20, 20)) self.pushButton_37.setObjectName("pushButton_37") self.gridLayout.addWidget(self.pushButton_37, 0, 0, 1, 1) self.pushButton_9 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_9.setFont(font) self.pushButton_9.setObjectName("pushButton_9") self.gridLayout.addWidget(self.pushButton_9, 1, 8, 1, 1) self.pushButton_19 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_19.setFont(font) self.pushButton_19.setObjectName("pushButton_19") self.gridLayout.addWidget(self.pushButton_19, 2, 8, 1, 1) self.pushButton_30 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_30.setFont(font) self.pushButton_30.setObjectName("pushButton_30") self.gridLayout.addWidget(self.pushButton_30, 3, 9, 1, 1) self.pushButton_4 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_4.setFont(font) self.pushButton_4.setObjectName("pushButton_4") self.gridLayout.addWidget(self.pushButton_4, 1, 3, 1, 1) self.pushButton_26 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_26.setFont(font) self.pushButton_26.setObjectName("pushButton_26") self.gridLayout.addWidget(self.pushButton_26, 3, 5, 1, 1) self.pushButton_8 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_8.setFont(font) self.pushButton_8.setObjectName("pushButton_8") self.gridLayout.addWidget(self.pushButton_8, 1, 7, 1, 1) self.pushButton_23 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_23.setFont(font) self.pushButton_23.setObjectName("pushButton_23") self.gridLayout.addWidget(self.pushButton_23, 3, 2, 1, 1) self.pushButton_33 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_33.setFont(font) self.pushButton_33.setObjectName("pushButton_33") self.gridLayout.addWidget(self.pushButton_33, 1, 11, 1, 1) self.pushButton_41 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_41.setFont(font) self.pushButton_41.setObjectName("pushButton_41") self.gridLayout.addWidget(self.pushButton_41, 0, 4, 1, 1) self.pushButton_27 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_27.setFont(font) self.pushButton_27.setObjectName("pushButton_27") self.gridLayout.addWidget(self.pushButton_27, 3, 6, 1, 1) self.pushButton_11 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_11.setFont(font) self.pushButton_11.setObjectName("pushButton_11") self.gridLayout.addWidget(self.pushButton_11, 2, 0, 1, 1) self.pushButton_3 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_3.setFont(font) self.pushButton_3.setObjectName("pushButton_3") self.gridLayout.addWidget(self.pushButton_3, 1, 2, 1, 1) self.pushButton = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.gridLayout.addWidget(self.pushButton, 1, 0, 1, 1) self.pushButton_13 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_13.setFont(font) self.pushButton_13.setObjectName("pushButton_13") self.gridLayout.addWidget(self.pushButton_13, 2, 2, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_2.setFont(font) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 1, 1, 1, 1) self.pushButton_10 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_10.setFont(font) self.pushButton_10.setObjectName("pushButton_10") self.gridLayout.addWidget(self.pushButton_10, 1, 9, 1, 1) self.pushButton_25 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_25.setFont(font) self.pushButton_25.setObjectName("pushButton_25") self.gridLayout.addWidget(self.pushButton_25, 3, 4, 1, 1) self.pushButton_21 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_21.setFont(font) self.pushButton_21.setObjectName("pushButton_21") self.gridLayout.addWidget(self.pushButton_21, 3, 0, 1, 1) self.pushButton_12 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_12.setFont(font) self.pushButton_12.setObjectName("pushButton_12") self.gridLayout.addWidget(self.pushButton_12, 2, 1, 1, 1) self.pushButton_7 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_7.setFont(font) self.pushButton_7.setObjectName("pushButton_7") self.gridLayout.addWidget(self.pushButton_7, 1, 6, 1, 1) self.pushButton_48 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_48.setFont(font) self.pushButton_48.setObjectName("pushButton_48") self.gridLayout.addWidget(self.pushButton_48, 0, 11, 1, 1) self.pushButton_20 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_20.setFont(font) self.pushButton_20.setObjectName("pushButton_20") self.gridLayout.addWidget(self.pushButton_20, 2, 9, 1, 1) self.pushButton_49 = QtWidgets.QPushButton(self.gridFrame) font = QtGui.QFont() font.setPointSize(15) self.pushButton_49.setFont(font) self.pushButton_49.setObjectName("pushButton_49") self.gridLayout.addWidget(self.pushButton_49, 3, 11, 1, 1) self.pushButton_50 = QtWidgets.QPushButton(self.gridFrame) self.pushButton_50.setObjectName("pushButton_50") self.gridLayout.addWidget(self.pushButton_50, 4, 11, 1, 1) self.pushButton_51 = QtWidgets.QPushButton(self.gridFrame) self.pushButton_51.setObjectName("pushButton_51") self.gridLayout.addWidget(self.pushButton_51, 4, 10, 1, 1) self.pushButton_52 = QtWidgets.QPushButton(self.gridFrame) self.pushButton_52.setObjectName("pushButton_52") self.gridLayout.addWidget(self.pushButton_52, 4, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.add_functions() def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton_38.setText(_translate("MainWindow", "2")) self.pushButton_16.setText(_translate("MainWindow", "р")) self.pushButton_6.setText(_translate("MainWindow", "н")) self.pushButton_36.setText(_translate("MainWindow", "/")) self.pushButton_45.setText(_translate("MainWindow", "9")) self.pushButton_29.setText(_translate("MainWindow", "ю")) self.pushButton_5.setText(_translate("MainWindow", "е")) self.pushButton_28.setText(_translate("MainWindow", "б")) self.pushButton_17.setText(_translate("MainWindow", "о")) self.pushButton_44.setText(_translate("MainWindow", "8")) self.pushButton_15.setText(_translate("MainWindow", "п")) self.pushButton_22.setText(_translate("MainWindow", "ч")) self.pushButton_39.setText(_translate("MainWindow", "3")) self.pushButton_43.setText(_translate("MainWindow", "7")) self.pushButton_18.setText(_translate("MainWindow", "л")) self.pushButton_32.setText(_translate("MainWindow", "х")) self.pushButton_34.setText(_translate("MainWindow", "э")) self.pushButton_24.setText(_translate("MainWindow", "м")) self.pushButton_14.setText(_translate("MainWindow", "а")) self.pushButton_40.setText(_translate("MainWindow", "4")) self.pushButton_47.setText(_translate("MainWindow", "(")) self.pushButton_42.setText(_translate("MainWindow", "6")) self.pushButton_46.setText(_translate("MainWindow", "0")) self.pushButton_35.setText(_translate("MainWindow", ",")) self.pushButton_37.setText(_translate("MainWindow", "1")) self.pushButton_9.setText(_translate("MainWindow", "щ")) self.pushButton_19.setText(_translate("MainWindow", "д")) self.pushButton_30.setText(_translate("MainWindow", ".")) self.pushButton_4.setText(_translate("MainWindow", "к")) self.pushButton_26.setText(_translate("MainWindow", "т")) self.pushButton_8.setText(_translate("MainWindow", "ш")) self.pushButton_23.setText(_translate("MainWindow", "с")) self.pushButton_33.setText(_translate("MainWindow", "ъ")) self.pushButton_41.setText(_translate("MainWindow", "5")) self.pushButton_27.setText(_translate("MainWindow", "ь")) self.pushButton_11.setText(_translate("MainWindow", "ф")) self.pushButton_3.setText(_translate("MainWindow", "у")) self.pushButton.setText(_translate("MainWindow", "й")) self.pushButton_13.setText(_translate("MainWindow", "в")) self.pushButton_2.setText(_translate("MainWindow", "ц")) self.pushButton_10.setText(_translate("MainWindow", "з")) self.pushButton_25.setText(_translate("MainWindow", "и")) self.pushButton_21.setText(_translate("MainWindow", "я")) self.pushButton_12.setText(_translate("MainWindow", "ы")) self.pushButton_7.setText(_translate("MainWindow", "г")) self.pushButton_48.setText(_translate("MainWindow", ")")) self.pushButton_20.setText(_translate("MainWindow", "ж")) self.pushButton_49.setText(_translate("MainWindow", "Ввод")) self.pushButton_50.setText(_translate("MainWindow", "Стереть")) self.pushButton_51.setText(_translate("MainWindow", "EN")) self.pushButton_52.setText(_translate("MainWindow", "Shift")) def add_functions(self): self.pushButton.clicked.connect(lambda: self.write_number(self.pushButton.text())) self.pushButton_2.clicked.connect(lambda: self.write_number(self.pushButton_2.text())) self.pushButton_3.clicked.connect(lambda: self.write_number(self.pushButton_3.text())) self.pushButton_4.clicked.connect(lambda: self.write_number(self.pushButton_4.text())) self.pushButton_5.clicked.connect(lambda: self.write_number(self.pushButton_5.text())) self.pushButton_6.clicked.connect(lambda: self.write_number(self.pushButton_6.text())) self.pushButton_7.clicked.connect(lambda: self.write_number(self.pushButton_7.text())) self.pushButton_8.clicked.connect(lambda: self.write_number(self.pushButton_8.text())) self.pushButton_9.clicked.connect(lambda: self.write_number(self.pushButton_9.text())) self.pushButton_10.clicked.connect(lambda: self.write_number(self.pushButton_10.text())) self.pushButton_11.clicked.connect(lambda: self.write_number(self.pushButton_11.text())) self.pushButton_12.clicked.connect(lambda: self.write_number(self.pushButton_12.text())) self.pushButton_13.clicked.connect(lambda: self.write_number(self.pushButton_13.text())) self.pushButton_14.clicked.connect(lambda: self.write_number(self.pushButton_14.text())) self.pushButton_15.clicked.connect(lambda: self.write_number(self.pushButton_15.text())) self.pushButton_16.clicked.connect(lambda: self.write_number(self.pushButton_16.text())) self.pushButton_17.clicked.connect(lambda: self.write_number(self.pushButton_17.text())) self.pushButton_18.clicked.connect(lambda: self.write_number(self.pushButton_18.text())) self.pushButton_19.clicked.connect(lambda: self.write_number(self.pushButton_19.text())) self.pushButton_20.clicked.connect(lambda: self.write_number(self.pushButton_20.text())) self.pushButton_21.clicked.connect(lambda: self.write_number(self.pushButton_21.text())) self.pushButton_22.clicked.connect(lambda: self.write_number(self.pushButton_22.text())) self.pushButton_23.clicked.connect(lambda: self.write_number(self.pushButton_23.text())) self.pushButton_24.clicked.connect(lambda: self.write_number(self.pushButton_24.text())) self.pushButton_25.clicked.connect(lambda: self.write_number(self.pushButton_25.text())) self.pushButton_26.clicked.connect(lambda: self.write_number(self.pushButton_26.text())) self.pushButton_27.clicked.connect(lambda: self.write_number(self.pushButton_27.text())) self.pushButton_28.clicked.connect(lambda: self.write_number(self.pushButton_28.text())) self.pushButton_29.clicked.connect(lambda: self.write_number(self.pushButton_29.text())) self.pushButton_30.clicked.connect(lambda: self.write_number(self.pushButton_30.text())) self.pushButton_31.clicked.connect(lambda: self.write_number(self.pushButton_31.text())) self.pushButton_32.clicked.connect(lambda: self.write_number(self.pushButton_32.text())) self.pushButton_33.clicked.connect(lambda: self.write_number(self.pushButton_33.text())) self.pushButton_34.clicked.connect(lambda: self.write_number(self.pushButton_34.text())) self.pushButton_35.clicked.connect(lambda: self.write_number(self.pushButton_35.text())) self.pushButton_36.clicked.connect(lambda: self.write_number(self.pushButton_36.text())) self.pushButton_37.clicked.connect(lambda: self.write_number(self.pushButton_37.text())) self.pushButton_38.clicked.connect(lambda: self.write_number(self.pushButton_38.text())) self.pushButton_39.clicked.connect(lambda: self.write_number(self.pushButton_39.text())) self.pushButton_40.clicked.connect(lambda: self.write_number(self.pushButton_40.text())) self.pushButton_41.clicked.connect(lambda: self.write_number(self.pushButton_41.text())) self.pushButton_42.clicked.connect(lambda: self.write_number(self.pushButton_42.text())) self.pushButton_43.clicked.connect(lambda: self.write_number(self.pushButton_43.text())) self.pushButton_44.clicked.connect(lambda: self.write_number(self.pushButton_44.text())) self.pushButton_45.clicked.connect(lambda: self.write_number(self.pushButton_45.text())) self.pushButton_46.clicked.connect(lambda: self.write_number(self.pushButton_46.text())) self.pushButton_47.clicked.connect(lambda: self.write_number(self.pushButton_47.text())) self.pushButton_48.clicked.connect(lambda: self.write_number(self.pushButton_48.text())) self.pushButton_49.clicked.connect(self.save) self.pushButton_51.clicked.connect(self.lang) self.pushButton_50.clicked.connect(self.udal) def udal(self): self.textEdit.setPlainText(self.textEdit.toPlainText() - str(number)) def lang(self): self.pushButton_51.setText("RU") self.pushButton_9.setText("Щ") def write_number(self, number): self.textEdit.setPlainText(self.textEdit.toPlainText() + str(number)) def save(self): file = self.textEdit.toPlainText() #присваиваем содержимому в поле тексэдит переменную print(file) import time timestr = time.strftime("%Y%m%d-%H%M%S") # засовываем в переменную текущую дату и время print (timestr) f1 = open(timestr + '.txt', 'w') # создаем переменую которая хранит в себе созданный текстовый фаил с текущей именем в виде даты и времени f1.write(file) # записываем содержимое поля текст эдит в фаил self.textEdit.clear() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
Офлайн
def udal(self): # self.textEdit.setPlainText(self.textEdit.toPlainText()) val = self.textEdit.toPlainText() self.textEdit.setPlainText(val[:-1] if len(val) else val)
Офлайн