国人开发的python窗体设计IDE,详情请看:PythonStudio:一款国人写的python及窗口开发编辑IDE,可以替代pyqt designer等设计器了-CSDN博客
这个软件作者还录制了入门的教程,跟着视频做,是个不错的python视频教程呢。从软件的使用,窗体的设计,到python的学习,对小白来说很友好啊。
最最最主要的,这个软件自带很多皮肤,漂亮的皮肤。
我跟着教程做这个学生信息管理系统,感觉使用它来做python窗口软件程序,真的很方便快捷。
Project1.py
from delphivcl import *from Unit1 import *def main():Application.Initialize()Application.Title = '学生管理系统'MainForm = Form1(Application)MainForm.Show()FreeConsole()Application.Run()if __name__ == '__main__':main()
Unit1.py
import osfrom delphivcl import *from Unit2 import *from Unit3 import *from Unit4 import *from Unit5 import *class Form1(Form):def __init__(self, owner):self.Button7 = Button(self)self.Button6 = Button(self)self.Button5 = Button(self)self.Button4 = Button(self)self.Button3 = Button(self)self.Button2 = Button(self)self.Button1 = Button(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))self.Button5.OnClick = self.Button5Clickself.Button4.OnClick = self.Button4Clickself.Button6.OnClick = self.Button6Clickself.Button1.OnClick = self.Button1Clickself.sm = StyleManager()self.sm.LoadFromFile("Windows10Malibu.vsf")self.sm.SetStyle('Windows10 Malibu')def Button1Click(self, Sender):frmAdd = Form2(self)frmAdd.ShowModal()def Button6Click(self, Sender):frmSearch = Form3(self)frmSearch.ShowModal()def Button4Click(self, Sender):frmDelete = Form4(self)frmDelete.ShowModal()def Button5Click(self, Sender):frmModify = Form5(self)frmModify.ShowModal()
Unit2.py
import osfrom delphivcl import *filename = 'Students.txt'# 定义学生信息文件class Form2(Form):def __init__(self, owner):self.BitBtn3 = BitBtn(self)self.BitBtn2 = BitBtn(self)self.BitBtn1 = BitBtn(self)self.LabeledEdit5 = LabeledEdit(self)self.LabeledEdit4 = LabeledEdit(self)self.LabeledEdit3 = LabeledEdit(self)self.LabeledEdit2 = LabeledEdit(self)self.LabeledEdit1 = LabeledEdit(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit2.pydfm"))self.BitBtn2.OnClick = self.BitBtn2Clickself.BitBtn1.OnClick = self.BitBtn1Clickdef insert(self):'''录入学生信息'''studentList = [] # 保存学生信息的列表stu_id = self.LabeledEdit1.Textif not stu_id: # stu_id 为空ShowMessage('ID不能为空!')returnstu_name = self.LabeledEdit2.Textif not stu_name:# stu_name 为空ShowMessage('姓名不能为空!')returntry:english = int(self.LabeledEdit3.Text)jsj = int(self.LabeledEdit4.Text)stu_math = int(self.LabeledEdit5.Text)except:ShowMessage('成绩应该是数值!')returnstudent = {'id':stu_id,'name':stu_name,'english':english,'jsj':jsj,'math':stu_math,}studentList.append(student)# 保存到文件里self.fileSave(studentList)ShowMessage('学生信息录入完成')def fileSave(self,student):'''将学生信息保存到文件'''try:stu_file = open(filename,'a')except Exception as e:stu_file = open(filename,'w') # 文件不存在就创建for info in student:stu_file.write(str(info)+'\n') # 按行存储stu_file.close()def BitBtn1Click(self, Sender):self.insert()def BitBtn2Click(self, Sender):self.LabeledEdit1.Clear()self.LabeledEdit2.Clear()self.LabeledEdit3.Clear()self.LabeledEdit4.Clear()self.LabeledEdit5.Clear()
Unit3.py
import osfrom delphivcl import *filename = 'Students.txt'# 定义学生信息文件class Form3(Form):def __init__(self, owner):self.Button2 = Button(self)self.Button1 = Button(self)self.Edit1 = Edit(self)self.Memo1 = Memo(self)self.RadioGroup1 = RadioGroup(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit3.pydfm"))self.Button2.OnClick = self.Button2Clickself.Button1.OnClick = self.Button1Clickdef search(self):'''查找学生信息'''student_query = []stu_id = ""stu_name=""if os.path.exists(filename):mode = self.RadioGroup1.ItemIndexif mode == 0:stu_id = self.Edit1.Textelif mode == 1:stu_name = self.Edit1.Textelse:ShowMessage('输入不能为空!')returnwith open(filename,'r') as file: # 打开文件student = file.readlines() # 读取所有行for list in student:dic = dict(eval(list))# 字符串转换成字典if stu_id is not "":# id 不为空if dic['id']==stu_id:student_query.append(dic)# 将找到的学生信息保存到列表elif stu_name is not "": # name 不为空if dic['name']==stu_name:student_query.append(dic)# 使用函数显示查询结果self.show_student(student_query)student_query.clear() # 清空列表else:# 文件不存在ShowMessage('数据信息未保存!!')def show_student(self,studentList):'''将保存在列表的学生信息显示出来'''if not studentList:self.Memo1.Lines.Add('无数据显示')return# 使用空格,显示的更整齐format_title = "{:^4}\t{:^4}\t{:^4}\t{:^6}\t{:^10}\t{:^10}"count = self.Memo1.Lines.Countif count < 2 :self.Memo1.Lines.Add(format_title.format("ID","姓名","英语","计算机","数学","总成绩"))for info in studentList:self.Memo1.Lines.Add(format_title.format(info.get('id'),info.get('name'),str(info.get('english')).center(5),str(info.get('jsj')).center(10),str(info.get('math')).center(12),str(info.get('english')+info.get('jsj')+info.get('math')).center(12),))def Button1Click(self, Sender):self.search()def Button2Click(self, Sender):self.RadioGroup1.ItemIndex=-1self.Edit1.Clear()self.Memo1.Clear()
Unit4.py
import osfrom delphivcl import *filename = 'Students.txt'# 定义学生信息文件class Form4(Form):def __init__(self, owner):self.Button2 = Button(self)self.Button1 = Button(self)self.LabeledEdit1 = LabeledEdit(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit4.pydfm"))self.Button2.OnClick = self.Button2Clickself.Memo1 = Memo(self)self.RadioGroup1 = RadioGroup(self)def delete(self):'''删除学生信息'''stu_id = self.LabeledEdit1.Textif stu_id is not "": # 输入不为空if os.path.exists(filename):with open(filename,'r') as file:student_old = file.readlines()else:student_old = []flag = Falseif student_old:# 如果存在with open(filename,'w') as wfile:doc = {}for list in student_old:doc = dict(eval(list))# 字符串转换成字典if doc['id'] != stu_id:wfile.write(str(doc)+'\n')else:flag = Trueif flag:self.Memo1.Lines.Add(f'ID为{stu_id}的学生信息已删除')else:self.Memo1.Lines.Add(f'未找到ID为{stu_id}的学生信息')else:self.Memo1.Lines.Add('无该学生信息')return# 显示全部学生信息def show_student(self,studentList):'''将保存在列表的学生信息显示出来'''if not studentList:self.Memo1.Lines.Add('无数据显示')return# 使用空格,显示的更整齐format_title = "{:^4}\t{:^4}\t{:^4}\t{:^6}\t{:^10}\t{:^10}"count = self.Memo1.Lines.Countif count < 2 :self.Memo1.Lines.Add(format_title.format("ID","姓名","英语","计算机","数学","总成绩"))for info in studentList:self.Memo1.Lines.Add(format_title.format(info.get('id'),info.get('name'),str(info.get('english')).center(5),str(info.get('jsj')).center(10),str(info.get('math')).center(12),str(info.get('english')+info.get('jsj')+info.get('math')).center(12),))def show_all(self):'''显示所有学生信息'''stu_new = []if os.path.exists(filename):with open(filename,'r') as rfile:stu_old = rfile.readlines()for list in stu_old:stu_new.append(eval(list))if stu_new:self.show_student(stu_new)else:self.Memo1.Lines.Add('暂未保存数据信息。。。')def Button2Click(self, Sender):self.delete()
Unit5.py
import osfrom delphivcl import *filename = 'Students.txt'# 定义学生信息文件class Form5(Form):def __init__(self, owner):self.BitBtn4 = BitBtn(self)self.BitBtn3 = BitBtn(self)self.BitBtn2 = BitBtn(self)self.BitBtn1 = BitBtn(self)self.LabeledEdit5 = LabeledEdit(self)self.LabeledEdit4 = LabeledEdit(self)self.LabeledEdit3 = LabeledEdit(self)self.LabeledEdit2 = LabeledEdit(self)self.LabeledEdit1 = LabeledEdit(self)self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit5.pydfm"))self.BitBtn4.OnClick = self.BitBtn4Clickself.BitBtn1.OnClick = self.BitBtn1Clickdef BitBtn1Click(self, Sender):'''修改学生信息'''stu_id = self.LabeledEdit1.Textname = self.LabeledEdit2.Textenglish = self.LabeledEdit3.Textjsj = self.LabeledEdit4.Textmath = self.LabeledEdit5.Textif stu_id is not "":if name is not "":if english is not "":if jsj is not "":if math is not "":stu = dict()stu['id'] = stu_idstu['name'] = namestu['english'] = int(english)stu['jsj'] = int(jsj)stu['math'] = int(math)flag = Falsewith open(filename,'r') as rfile:student_old = rfile.readlines()with open(filename,'w') as wfile:for student in student_old:stud = dict(eval(student))if stud['id'] == stu_id:flag = Truestudent = str(stu)# 将字典转换为字符串wfile.write(student)if flag:ShowMessage('修改成功。。')else:ShowMessage('id不存在或数据未变化。。')else:ShowMessage('数学不能为空')returnelse:ShowMessage('计算机不能为空')returnelse:ShowMessage('英语不能为空')returnelse:ShowMessage('姓名不能为空')returnelse:ShowMessage('id不能为空')returndef BitBtn4Click(self, Sender):'''查询学生信息'''stu_id = self.LabeledEdit1.Textif stu_id is not "": # 输入不为空if os.path.exists(filename):with open(filename,'r') as file:student_old = file.readlines()else:student_old = []ShowMessage('未保存数据')flag = Falseif student_old:# 如果存在for list in student_old:doc = dict(eval(list))# 字符串转换成字典if doc['id'] == stu_id:flag = Trueself.LabeledEdit2.Text=doc['name']self.LabeledEdit3.Text=doc['english']self.LabeledEdit4.Text=doc['jsj']self.LabeledEdit5.Text=doc['math']if flag == False:ShowMessage('id不存在')self.LabeledEdit2.Text=''self.LabeledEdit3.Text=''self.LabeledEdit4.Text=''self.LabeledEdit5.Text=''else:ShowMessage('数据为空')else:ShowMessage('id不能为空')return# 显示全部学生信息
本来还有排序和显示2个窗体的,我没有做。我使用的是皮肤 Windows10 Malibu。
self.sm = StyleManager()self.sm.LoadFromFile("Windows10Malibu.vsf")self.sm.SetStyle('Windows10 Malibu')
3行代码,加个123kb的文件,就给几个窗口都换了皮肤了,真的方便啊。