from tkinter import * from tkinter.ttk import Combobox from tkinter.scrolledtext import ScrolledText import tkinter.messagebox import sys import time import user import var import batch import param import production import inquire import user_socket import pro import user_openOpc import ezcad opc_value = var.opc_var() init_window = Tk() #实例化出一个父窗口 user_var = var.Var_value(init_window) font_size_title = 14 font_size_text = 11 # 创建新线程 thread_tcp = user_socket.socket_server(1, "Thread-tcp", 1) thread_work = pro.work_server(2, "Thread-work", 2) thread_opc = user_openOpc.opc_server(3, "Thread-opc", 3) thread_ezcad = ezcad.ezcad(4, "Thread-ezcad", 4) class my_gui(Frame): def __init__(self, init_window_name): global user_var self.init_window_name = init_window_name self.user_var = user_var self.opc_value = opc_value self.tcpserverParam = user_socket.tcpserverParam self.screen_width = self.user_var.screen_width self.screen_height = self.user_var.screen_height self.font_size_title = font_size_title self.font_size_text = font_size_text self.bee_stat_change_timeout = 0 self.main_gui_init() self.title_canvas_init() self.button_canvas_init() self.order_frame_init() self.user_var.windows_idx = 'app' self.fun_timer() def team_sel_value(self): self.team_combobox.current(self.user_var.team_sel) def team_combobox_sel(self, *args): value = self.team_combobox.get() stat = tkinter.messagebox.askokcancel(title='提示', message='班组确认切换为{}'.format(value)) if stat == True: for i in range(len(self.user_var.team_list)): if self.user_var.team_list[i] == value: self.user_var.team_sel = i self.user_var.team_value = value self.user_var.team = chr(self.user_var.team_sel + ord('A')) self.user_var.order_update_stat = True break self.team_sel_value() # def check_radiobutton_sel(self): # print(self.check_bit.get()) def user_button_event(self): print("Please enter your username and password!") self.user_var.last_windows_idx = 'app' self.init_window_name.after_cancel(self.task_user) self.main_frame.destroy() user.my_reg(self.init_window_name) def param_button_event(self): if self.user_var.auth_stat == True: print("Enter Param Set!") self.user_var.last_windows_idx = 'app' self.init_window_name.after_cancel(self.task_user) self.main_frame.destroy() param.my_param(self.init_window_name) else: tkinter.messagebox.showwarning(title='提示', message='请登录后操作!') def data_button_event(self): print("Enter Data View!") self.user_var.last_windows_idx = 'app' self.init_window_name.after_cancel(self.task_user) self.main_frame.destroy() inquire.my_inquire(self.init_window_name) def print_button_event(self): print("Enter Print!") self.user_var.last_windows_idx = 'app' def produce_sel_button_event(self): if self.user_var.auth_stat == True: print("Please Select Production!") self.user_var.last_windows_idx = 'app' self.init_window_name.after_cancel(self.task_user) self.main_frame.destroy() production.my_production(self.init_window_name) else: tkinter.messagebox.showwarning(title='提示', message='请登录后操作!') def bee_button_event(self): if self.user_var.bee_stat == False: self.user_var.bee_stat = True self.bee_button.configure(relief=RAISED) self.bee_button.configure(state="disabled") self.bee_stat_change_timeout = 10 self.opc_value.set_Bee(True) else: self.user_var.bee_stat = False self.bee_button.configure(relief=SUNKEN) self.bee_button.configure(state="disabled") self.bee_stat_change_timeout = 10 self.opc_value.set_Bee(False) def workstatlabel_value(self): if self.user_var.airdata_work_stat == 'working': self.workstatlabel.config(text=" 系统正在运行中...") else: self.workstatlabel.config(text=" 系统停止中...") def productstatlabel_value(self): if self.user_var.product_name_noset == '品番已设置': self.productstatlabel.config(fg='black') self.productstatlabel.config(text=self.user_var.product_name_noset) else: self.productstatlabel.config(fg='Red') self.productstatlabel.config(text=self.user_var.product_name_noset) def opcstatlabel_value(self): if self.user_var.opc_conn_stat == "PLC已连接": self.opcstatlabel.config(fg="Green") elif self.user_var.opc_conn_stat == "PLC未连接": self.opcstatlabel.config(fg="Yellow") else: self.opcstatlabel.config(fg="Red") self.opcstatlabel.config(text=self.user_var.opc_conn_stat) def socketstatlabel_value(self): if self.user_var.socket_conn_stat == True: self.socketstatlabel.config(text="打标机已连接") self.socketstatlabel.config(fg="Green") else: self.socketstatlabel.config(text="打标机未连接") self.socketstatlabel.config(fg="Red") def authstatlabel_value(self): if self.user_var.auth_stat == False: self.authlabel.config(text="不允许", fg='red') # self.team_combobox.configure(state="disabled") self.param_button.configure(state="disabled") self.print_button.configure(state="disabled") self.product_sel_button.configure(state="disabled") else: self.authlabel.config(text="允许", fg='green') # self.team_combobox.configure(state="readonly") self.param_button.configure(state="normal") self.print_button.configure(state="normal") self.product_sel_button.configure(state="normal") def airtightdev_value(self): if self.user_var.originchkok_stat == True: self.originchkoklabel.config(bg='Lime') else: self.originchkoklabel.config(bg='DarkGray') if self.user_var.upairtightok_stat == True: self.upairtightoklabel.config(bg='Lime') else: self.upairtightoklabel.config(bg='DarkGray') if self.user_var.upairtightng_stat == True: self.upairtightnglabel.config(bg='Lime') else: self.upairtightnglabel.config(bg='DarkGray') if self.user_var.upprintok_stat == True: self.upprintoklabel.config(bg='Lime') else: self.upprintoklabel.config(bg='DarkGray') if self.user_var.origindir_stat == True: self.origindirlabel.config(bg='Lime') else: self.origindirlabel.config(bg='DarkGray') if self.user_var.downairtightok_stat == True: self.downairtightoklabel.config(bg='Lime') else: self.downairtightoklabel.config(bg='DarkGray') if self.user_var.downairtightng_stat == True: self.downairtightnglabel.config(bg='Lime') else: self.downairtightnglabel.config(bg='DarkGray') if self.user_var.downprintok_stat == True: self.downprintoklabel.config(bg='Lime') else: self.downprintoklabel.config(bg='DarkGray') def motordev_value(self): if self.user_var.motororiginok_stat == True: self.motororiginoklabel.config(bg='Lime') else: self.motororiginoklabel.config(bg='DarkGray') if self.user_var.motoronup_stat == True: self.motoronuplabel.config(bg='Lime') else: self.motoronuplabel.config(bg='DarkGray') if self.user_var.motorondown_stat == True: self.motorondownlabel.config(bg='Lime') else: self.motorondownlabel.config(bg='DarkGray') if self.user_var.motorunuse_stat == True: self.motorunuselabel.config(bg='Lime') else: self.motorunuselabel.config(bg='DarkGray') def station_value(self): if self.user_var.upgages_stat == True: self.upgageslabel.config(bg='black', fg='white') else: self.upgageslabel.config(fg='black', bg='white') if self.user_var.upworks_stat == True: self.upworkslabel.config(bg='black', fg='white') else: self.upworkslabel.config(fg='black', bg='white') if self.user_var.upmpen_stat == True: self.upmpenlabel.config(bg='black', fg='white') else: self.upmpenlabel.config(fg='black', bg='white') if self.user_var.upconnect_stat == True: self.upconnectlabel.config(bg='black', fg='white') else: self.upconnectlabel.config(fg='black', bg='white') if self.user_var.downgages_stat == True: self.downgageslabel.config(bg='black', fg='white') else: self.downgageslabel.config(fg='black', bg='white') if self.user_var.downworks_stat == True: self.downworkslabel.config(bg='black', fg='white') else: self.downworkslabel.config(fg='black', bg='white') if self.user_var.downmpen_stat == True: self.downmpenlabel.config(bg='black', fg='white') else: self.downmpenlabel.config(fg='black', bg='white') if self.user_var.downconnect_stat == True: self.downconnectlabel.config(bg='black', fg='white') else: self.downconnectlabel.config(fg='black', bg='white') def bee_value(self): if self.bee_stat_change_timeout == 0: if self.user_var.bee_stat == True: self.bee_button.configure(relief=RAISED) self.bee_button.configure(state="normal") else: self.bee_button.configure(relief=SUNKEN) self.bee_button.configure(state="normal") else: self.bee_stat_change_timeout = self.bee_stat_change_timeout - 1 def auth_exit(self): if self.user_var.auth_timeout > 0: self.user_var.auth_timeout = self.user_var.auth_timeout - 1 else: self.user_var.auth_stat = False def windows_update(self): currentTime = time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time())) self.timelabel.config(text=currentTime) self.workstatlabel_value() self.productstatlabel_value() self.opcstatlabel_value() self.socketstatlabel_value() self.authstatlabel_value() self.airtightdev_value() self.motordev_value() self.station_value() self.bee_value() self.team_sel_value() self.auth_exit() self.init_window_name.update() self.fun_timer() def fun_timer(self): self.task_user=self.init_window_name.after(1000, self.windows_update) def main_gui_init(self): self.main_frame = Frame(self.init_window_name, width=self.screen_width, height=self.screen_height) self.main_frame.pack() # 标题栏 def title_canvas_init(self): self.title_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=35, bg='SeaGreen') self.mainlabel = Label(self.title_canvas, text="主页面", fg='yellow', font=("宋体", self.font_size_title), bg='SeaGreen', anchor='w') self.mainlabel.place(x=20, y=5) self.timelabel = Label(self.title_canvas, text=time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(time.time())), fg='yellow', font=("宋体", self.font_size_title), bg='SeaGreen', anchor='e') self.timelabel.place(x=self.title_canvas.winfo_reqwidth() - self.timelabel.winfo_reqwidth() - 20, y=5) self.title_canvas.create_line(self.mainlabel.winfo_reqwidth()/2+20, 32, self.title_canvas.winfo_reqwidth() - self.timelabel.winfo_reqwidth()/2 - 20, 32, fill='white') self.title_canvas.place(x=10, y=10) # 控制栏 def button_canvas_init(self): self.button_canvas = Canvas(self.main_frame, width=self.screen_width - 20, height=40) self.user_button = Button(self.button_canvas, text="用户登陆", fg='white', bg='DeepSkyBlue', width=8, activebackground='white', activeforeground='DeepSkyBlue', font=("宋体", self.font_size_title, "bold"), command=self.user_button_event) self.user_button.place(x=1, y=0) self.param_button = Button(self.button_canvas, text="参数设定", fg='white', bg='DeepSkyBlue', width=8, activebackground='white', activeforeground='DeepSkyBlue', state="disabled", font=("宋体", self.font_size_title, "bold"), command=self.param_button_event) self.param_button.place(x=self.user_button.winfo_reqwidth()*2+3, y=0) self.data_button = Button(self.button_canvas, text="数据查询", fg='white', bg='DeepSkyBlue', width=8, activebackground='white', activeforeground='DeepSkyBlue', font=("宋体", self.font_size_title, "bold"), command=self.data_button_event) self.data_button.place(x=self.user_button.winfo_reqwidth() + 2, y=0) self.print_button = Button(self.button_canvas, text="手动刻印", fg='white', bg='DeepSkyBlue', width=8, activebackground='white', activeforeground='DeepSkyBlue', font=("宋体", self.font_size_title, "bold"), command=self.print_button_event) # self.print_button.place(x=self.user_button.winfo_reqwidth()*3 + 4, y=0) self.bee_button = Button(self.button_canvas, text="蜂鸣器关闭", fg='black', width=12, font=("宋体", self.font_size_text), command=self.bee_button_event) if self.user_var.bee_stat == True: self.bee_button.configure(relief=RAISED) else: self.bee_button.configure(relief=SUNKEN) self.bee_button.place(x=self.button_canvas.winfo_reqwidth() - self.bee_button.winfo_reqwidth()-5, y=5) self.button_canvas.place(x=10, y=self.screen_height - 60) # 工单栏 def order_frame_init(self): self.order_frame = Frame(self.main_frame, width=self.screen_width - 20, relief=SUNKEN, borderwidth=2, height=self.screen_height - self.title_canvas.winfo_reqheight() - self.button_canvas.winfo_reqheight() - 35) # 工单栏展示 self.order_frame.place(x=12, y=self.title_canvas.winfo_reqheight() + 15) # 产品信息 self.product_frame = Frame(self.order_frame, width=self.order_frame.winfo_reqwidth() - 4, height=100, relief=SUNKEN, borderwidth=2) self.worklabel = Label(self.product_frame, text=" 状态信息 ", fg='black', font=("宋体", self.font_size_text), bg='PaleGreen', anchor='w') self.worklabel.place(x=1, y=1) # 系统当前状态 self.workstatcanvas = Canvas(self.product_frame, bg='black', width=self.product_frame.winfo_reqwidth() - 8, height=25) self.workstatlabel = Label(self.workstatcanvas, fg='Gold', font=("宋体", self.font_size_text), bg='black', anchor='w') self.workstatlabel.place(x=2, y=5) self.productstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black', anchor='w') self.productstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 500, y=5) self.opcstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black', anchor='w') self.opcstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 250, y=5) self.socketstatlabel = Label(self.workstatcanvas, fg='Red', font=("宋体", self.font_size_text), bg='black', anchor='w') self.socketstatlabel.place(x=self.workstatcanvas.winfo_reqwidth() - 100, y=5) self.workstatcanvas.place(x=0, y=self.worklabel.winfo_reqheight() + 1) # 操作授权 self.authstatframe = Frame(self.product_frame, bg='GreenYellow', width=150, height=30, relief=RAISED, borderwidth=2) self.authtitlelabel = Label(self.authstatframe, text="操作许可:", fg='black', font=("宋体", self.font_size_text), bg='GreenYellow', anchor='w') self.authtitlelabel.place(x=1, y=1) self.authlabel = Label(self.authstatframe, font=("宋体", self.font_size_text), width=6, bg='GreenYellow', anchor='w') self.authlabel.place(x=self.authtitlelabel.winfo_reqwidth(), y=1) # self.authstatlabel_value() self.authstatframe.config(height=self.authtitlelabel.winfo_reqheight()+8, width=self.authtitlelabel.winfo_reqwidth() + self.authlabel.winfo_reqwidth() + 4) self.authstatframe.place(x=1, y=self.worklabel.winfo_reqheight()+self.workstatcanvas.winfo_reqheight() + 4) # 产品编号 self.product_sel_button = Button(self.product_frame, text="品番设定", fg='black', width=10, font=("宋体", self.font_size_text), command=self.produce_sel_button_event) self.product_sel_button.place( x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - 8, y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4) self.productidxlabel = Label(self.product_frame, fg='Green', font=("宋体", self.font_size_title, "bold"), bg='black', width=2, height=1, anchor='center', textvariable=self.user_var.product_idx_str) self.productstrlabel = Label(self.product_frame, fg='white', font=("宋体", self.font_size_title, "bold"), bg='black', width=30, height=1, anchor='center', textvariable=self.user_var.product_str) self.productidxlabel.place( x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - self.productidxlabel.winfo_reqwidth() - 12, y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4) self.productstrlabel.place( x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - 10, y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 4) self.productnamelabel = Label(self.product_frame, text="产品\r编号", font=("宋体", self.font_size_text - 1), width=4, justify='left') self.productnamelabel.place( x=self.product_frame.winfo_reqwidth() - self.product_sel_button.winfo_reqwidth() - self.productstrlabel.winfo_reqwidth() - self.productidxlabel.winfo_reqwidth() - self.productnamelabel.winfo_reqwidth() - 14, y=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + 2) # 产品信息展示 self.product_frame.config( height=self.worklabel.winfo_reqheight() + self.workstatcanvas.winfo_reqheight() + self.authstatframe.winfo_reqheight() + 10) self.product_frame.place(x=1, y=1) # 生产数据 self.order_data_frame = Frame( self.order_frame, width=self.screen_width / 4, height=self.order_frame.winfo_reqheight() - self.product_frame.winfo_reqheight() - 15, relief=SUNKEN, borderwidth=2) # 生产数据展示 self.order_data_frame.place(x=1, y=self.product_frame.winfo_reqheight() + 10) self.orderdatalabel_canvas = Canvas(self.order_data_frame, bg='DeepSkyBlue', width=self.order_data_frame.winfo_reqwidth() - 10, height=25) self.orderdatalabel = Label(self.orderdatalabel_canvas, fg='black', font=("宋体", self.font_size_text), bg='DeepSkyBlue', height=1, anchor='center', text="生产数据") self.orderdatalabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 50, y=5) self.orderdatalabel_canvas.place(x=1, y=1) self.oktitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="OK数:") self.oktitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=40) self.oklabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE, height=1, width=10, borderwidth=1, anchor='center', textvariable=self.user_var.order_ok_str) self.oklabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=40) self.ngtitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="NG数:") self.ngtitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=80) self.nglabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE, height=1, width=10, borderwidth=1, anchor='center', textvariable=self.user_var.order_ng_str) self.nglabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=80) self.targetitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="targe:") self.targetitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=120) self.targelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE, height=1, width=10, borderwidth=1, anchor='center', textvariable=self.user_var.order_targe_str) self.targelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=120) self.snptitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="SNP:") self.snptitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=160) self.snplabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE, height=1, width=10, borderwidth=1, anchor='center', textvariable=self.user_var.order_snp_str) self.snplabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=160) self.yeartitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="年份批号:") self.yeartitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=200) self.yearlabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), relief=GROOVE, height=1, width=10, borderwidth=1, anchor='center', textvariable=self.user_var.order_year_str) self.yearlabel.place(x=self.order_data_frame.winfo_reqwidth() / 2, y=200) self.teamtitlelabel = Label(self.order_data_frame, fg='black', font=("宋体", self.font_size_title), height=1, width=10, borderwidth=1, anchor='e', text="班组选择:") self.teamtitlelabel.place(x=self.order_data_frame.winfo_reqwidth() / 2 - 120, y=240) self.team_canvas = Canvas(self.order_data_frame, bg='yellow', width=102, height=28) self.team_combobox = Combobox(self.team_canvas, font=("宋体", self.font_size_text), width=9) self.team_combobox["value"] = self.user_var.team_list # self.team_combobox.configure(state="readonly") self.team_combobox.configure(state="readonly") self.team_sel_value() self.team_combobox.bind("<>", self.team_combobox_sel) self.team_combobox.place(x=5, y=5) self.team_canvas.place(x=self.order_data_frame.winfo_reqwidth()/2 - 3, y=238) self.notice_canvas = Canvas(self.order_data_frame) self.noticelabel01 = Label(self.notice_canvas, fg='red', font=("宋体", self.font_size_text), anchor='center', text="注:图中") self.noticelabel01.grid(row=0, column=0) self.noticelabel02 = Label(self.notice_canvas, bg='yellow', relief=SOLID, font=("宋体", self.font_size_text - 2), anchor='center', text=" ") self.noticelabel02.grid(row=0, column=1) self.noticelabel03 = Label(self.notice_canvas, fg='red', font=("宋体", self.font_size_text), anchor='center', text="区域作业员需要选择") self.noticelabel03.grid(row=0, column=2) self.notice_canvas.place(x=3, y=self.order_data_frame.winfo_reqheight() - 25) # 气密数据 self.airtightness_data_frame = Frame( self.order_frame, width=self.order_frame.winfo_reqwidth() - self.order_data_frame.winfo_reqwidth() - 8, height=160, relief=SUNKEN, borderwidth=2) # 气密数据展示 self.airtightness_data_frame.place( x=self.order_data_frame.winfo_reqwidth() + 2, y=self.product_frame.winfo_reqheight() + 10) self.airtightnesstitle_canvas = Canvas(self.airtightness_data_frame, bg='DeepSkyBlue', width=self.airtightness_data_frame.winfo_reqwidth() / 3, height=25) self.airtightnesstitlelabel = Label(self.airtightnesstitle_canvas, fg='black', font=("宋体", self.font_size_text), bg='DeepSkyBlue', anchor='center', text="气密数据区") self.airtightnesstitlelabel.place(x=self.airtightnesstitle_canvas.winfo_reqwidth() / 2 - 40, y=5) self.airtightnesstitle_canvas.place(x=self.airtightness_data_frame.winfo_reqwidth() / 3, y=1) self.batchtitlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text), borderwidth=1, anchor='e', text="当前批号:", width=10) self.batchtitlelabel.place(x=10, y=40) self.batchlabel = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text), relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.batch_str, width=35, height=1) self.batchlabel.place(x=100, y=40) self.airtightness_17700titlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text), borderwidth=1, anchor='e', text="气密数据\r(17700):", width=10) self.airtightness_17700titlelabel.place(x=10, y=70) self.airtightness_17700label = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text), relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.airtightness_17700_str, width=35, height=1) self.airtightness_17700label.place(x=100, y=80) self.airtightness_17720titlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text), borderwidth=1, anchor='e', text="气密数据\r(17720):", width=10) self.airtightness_17720titlelabel.place(x=10, y=110) self.airtightness_17720label = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text), relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.airtightness_17720_str, width=35, height=1) self.airtightness_17720label.place(x=100, y=120) self.printf_numtitlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text), borderwidth=1, anchor='center', text="标签号:", width=10) self.printf_numtitlelabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 30, y=40) self.printf_numlabel = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text), relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.printf_num_str, width=25, height=1) self.printf_numlabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 120, y=40) self.serial_numtitlelabel = Label(self.airtightness_data_frame, fg='black', font=("宋体", self.font_size_text), borderwidth=1, anchor='center', text="流水号:", width=10) self.serial_numtitlelabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 30, y=80) self.serial_numlabel = Label(self.airtightness_data_frame, fg='black', bg='white', font=("宋体", self.font_size_text), relief=GROOVE, borderwidth=1, anchor='center', textvariable=self.user_var.serial_num_str, width=25, height=1) self.serial_numlabel.place(x=self.airtightness_data_frame.winfo_reqwidth() / 2 + 120, y=80) # 设备信号 self.dev_signal_frame = Frame( self.order_frame, width=self.order_frame.winfo_reqwidth() - self.order_data_frame.winfo_reqwidth() - 8, height=self.order_data_frame.winfo_reqheight() - self.airtightness_data_frame.winfo_reqheight()-5, relief=SUNKEN, borderwidth=2) # 设备信号展示 self.dev_signal_frame.place( x=self.order_data_frame.winfo_reqwidth() + 2, y=self.product_frame.winfo_reqheight() + self.airtightness_data_frame.winfo_reqheight() + 15) self.devsignaltitle_canvas = Canvas(self.dev_signal_frame, bg='DeepSkyBlue', width=self.dev_signal_frame.winfo_reqwidth() / 3, height=30) self.devsignaltitlelabel = Label(self.devsignaltitle_canvas, fg='black', font=("宋体", self.font_size_text), bg='DeepSkyBlue', anchor='center', text="设备信号显示区") self.devsignaltitlelabel.place(x=self.airtightnesstitle_canvas.winfo_reqwidth() / 2 - 70, y=5) self.devsignaltitle_canvas.place(x=self.airtightness_data_frame.winfo_reqwidth() / 3, y=1) self.airtightdevtitlelabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), anchor='center', text="气密机") self.motordevtitlelabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), anchor='center', text="移动电机") self.airtightdevtitlelabel.place(x=10, y=1) self.motordevtitlelabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 80, y=1) self.originchkoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="点检OK", width=10, height=1) self.originchkoklabel.place(x=10, y=40) self.upairtightoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="上气密OK", width=10, height=1) self.upairtightoklabel.place(x=100, y=40) self.upairtightnglabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="上气密NG", width=10, height=1) self.upairtightnglabel.place(x=190, y=40) self.upprintoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="上刻印完成", width=10, height=1) self.upprintoklabel.place(x=280, y=40) self.origindirlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="原点指示", width=10, height=1) self.origindirlabel.place(x=10, y=70) self.downairtightoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="下气密OK", width=10, height=1) self.downairtightoklabel.place(x=100, y=70) self.downairtightnglabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="下气密NG", width=10, height=1) self.downairtightnglabel.place(x=190, y=70) self.downprintoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="下刻印完成", width=10, height=1) self.downprintoklabel.place(x=280, y=70) self.airtightdev_value() self.motororiginoklabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="电机原点正确", width=12, height=1) self.motororiginoklabel.place(x=self.dev_signal_frame.winfo_reqwidth()-220, y=40) self.motoronuplabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="电机于上工位", width=12, height=1) self.motoronuplabel.place(x=self.dev_signal_frame.winfo_reqwidth()-110, y=40) self.motorunuselabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="未使用", width=12, height=1) self.motorunuselabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 220, y=70) self.motorondownlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="电机于下工位", width=12, height=1) self.motorondownlabel.place(x=self.dev_signal_frame.winfo_reqwidth() - 110, y=70) self.motordev_value() self.upstationlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), anchor='center', text="上工作位", width=10, height=1) self.upstationlabel.place(x=10, y=125) self.upgages_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.upgageslabel = Label(self.upgages_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="gage-s", width=6, height=1) self.upgageslabel.place(x=6, y=6) self.upgages_canvas.place(x=100, y=120) self.upworks_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.upworkslabel = Label(self.upworks_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="work-s", width=6, height=1) self.upworkslabel.place(x=6, y=6) self.upworks_canvas.place(x=170, y=120) self.upmpen_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.upmpenlabel = Label(self.upmpen_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="M-pen", width=6, height=1) self.upmpenlabel.place(x=6, y=6) self.upmpen_canvas.place(x=240, y=120) self.upconnect_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=67, height=25) self.upconnectlabel = Label(self.upconnect_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="connect", width=7, height=1) self.upconnectlabel.place(x=6, y=6) self.upconnect_canvas.place(x=310, y=120) self.downstationlabel = Label(self.dev_signal_frame, fg='black', font=("宋体", self.font_size_text), anchor='center', text="下工作位", width=10, height=1) self.downstationlabel.place(x=10, y=165) self.downgages_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.downgageslabel = Label(self.downgages_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="gage-s", width=6, height=1) self.downgageslabel.place(x=6, y=6) self.downgages_canvas.place(x=100, y=160) self.downworks_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.downworkslabel = Label(self.downworks_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="work-s", width=6, height=1) self.downworkslabel.place(x=6, y=6) self.downworks_canvas.place(x=170, y=160) self.downmpen_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=60, height=25) self.downmpenlabel = Label(self.downmpen_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="M-pen", width=6, height=1) self.downmpenlabel.place(x=6, y=6) self.downmpen_canvas.place(x=240, y=160) self.downconnect_canvas = Canvas(self.dev_signal_frame, bg='white', relief=SOLID, borderwidth=1, width=67, height=25) self.downconnectlabel = Label(self.downconnect_canvas, font=("宋体", self.font_size_text), relief=SOLID, borderwidth=1, anchor='center', text="connect", width=7, height=1) self.downconnectlabel.place(x=6, y=6) self.downconnect_canvas.place(x=310, y=160) class my_main(Frame): def __init__(self, init_window_name): global user_var self.init_window_name = init_window_name self.user_var = user_var self.screen_width = self.init_window_name.winfo_screenwidth() self.screen_height = self.init_window_name.winfo_screenheight() self.set_init_window() my_gui(self.init_window_name) # 设置窗口 def set_init_window(self): self.init_window_name.title("气密测试") # 窗口名 self.init_window_name.resizable(width=False, height=False) # self.init_window_name.geometry('%dx%d' % (self.screen_width, self.screen_height)) #定义窗口弹出时的默认展示大小和位置 # self.init_window_name.state("zoomed") # self.init_window_name.overrideredirect(True) # self.init_window_name["bg"] = "black" #窗口背景色,其他背景色见:blog.csdn.net/chl0000/article/details/7657887 # self.init_window_name.attributes("-alpha", 1) #虚化,值越小虚化程度越高 # label.grid(row=0, column=2, rowspan=2, columnspan=2, sticky=W + E + N + S, padx=5, pady=5) # 合并两行,两列,居中,四周外延5个长度 def on_closing(self): if self.user_var.auth_stat == True: message = tkinter.messagebox.askokcancel(title='提示', message='是否退出程序?') if(message == True): print("application is closed!") while self.user_var.pro_exit_stat == False: thread_work.exit() thread_opc.exit() thread_tcp.exit() time.sleep(2) init_window.destroy() sys.exit(0) else: tkinter.messagebox.showwarning(title='提示', message='请登录后操作!') def gui_start(): global init_window global user_var ZMJ_PORTAL = my_main(init_window) thread_opc.start() thread_tcp.start() thread_work.start() thread_ezcad.start() # 设置根窗口默认属性 ZMJ_PORTAL.set_init_window() init_window.protocol("WM_DELETE_WINDOW", ZMJ_PORTAL.on_closing) init_window.mainloop() #父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示