它只显示运行此脚本时的错误消息:
import tkinter as tk
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QImage, QPalette, QBrush
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(500, 500))
self.setWindowTitle("Chercher des Personnes")
oImage = QImage("i.jpg")
sImage = oImage.scaled(QSize(300,200)) # resize Image to widgets size
palette = QPalette()
palette.setBrush(10, QBrush(sImage)) # 10 = Windowrole
self.setPalette(palette)
self.nameLabel = QLabel(self)
self.label = QLabel(self)
self.Name = QLabel(self)
self.Age = QLabel(self)
self.Telnum = QLabel(self)
self.Mail = QLabel(self)
self.Adress = QLabel(self)
self.nameLabel.setText('Prenom du personne:')
self.Name.setText('Nom et Prenom: ')
self.Age.setText('Age: ')
self.Telnum.setText('Numero de Tel: ')
self.Mail.setText('Email adress: ')
self.Adress.setText('Adress: ')
self.line = QLineEdit(self)
self.line.move(150, 50)
self.line.resize(200, 32)
self.nameLabel.move(150, 20)
self.Name.move(20, 150)
self.Age.move(20, 180)
self.Telnum.move(20, 210)
self.Mail.move(20, 240)
self.Adress.move(20, 270)
pybutton = QPushButton('OK', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(200, 32)
pybutton.move(150, 85)
def clickMethod(self):
class people:
def __init__(self, full_name, birthday, telnum, mail, adress, other):
self.name = full_name
self.full_name = full_name
self.birthday = birthday #ddmmyyyy
self.telnum = telnum
self.mail = mail
self.adress = adress
self.other = other
#Peoples info
john = people("Full name: John Doe", "Birthday: ??/01/2005 Age: 12", "Telephone number: +41 12 345 67 89", "Educanet2: fake@example", "Adress: 123 Fake Street, 1721 Suisse", "Other: John is a known programmer and plays ice hockey. He participates in robotics competitions. But he's bullied and made fun of at times")
self.Name.setText(str(locals()[self.line.text().lower()].name ))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )
这里的脚本上的缩进空格不正确,但它在我的真实代码上。我需要花费很长时间才能为每一行制作4个空格。
为什么我收到这条消息:“Python停止工作”? 我该怎么做才能解决它?
Ps:当使用其他脚本时,不会出现这样的错误消息,或者当我用tkinter消息框替换self.name.setText(“”)时不会发生错误