python - 停止运行脚本时如何保持 tkinter 窗口打开?
问题描述
我想知道你们中是否有人知道在停止运行脚本时如何保持 tkinter 窗口打开。这个想法是有数据进来,但是要重新运行整个程序,我需要停止显示脚本,并且我希望显示窗口在更改期间保持打开状态。
这是显示代码所有0都在datta
谢谢!
from tkinter import *
from tkinter.scrolledtext import ScrolledText
class GroupFrame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, bg="gray94", borderwidth=2, relief=GROOVE)
self.parent = parent
self.widgets()
def widgets(self):
self.label = Label(self, text="Family :", bg="gray94")
self.label.grid(row=1, column=0, sticky='e')
self.label = Label(self, text="Sub family :", bg="gray94")
self.label.grid(row=2, column=0, sticky='e')
self.label = Label(self, text="Captor :", bg="gray94")
self.label.grid(row=3, column=0, sticky='e')
self.label = Label(self, text="Nb of Insp lot :", bg="gray94")
self.label.grid(row=4, column=0, sticky='e')
self.label = Label(self, text="Nb of equipement :", bg="gray94")
self.label.grid(row=5, column=0, sticky='e')
self.label = Label(self, text="Equipement :", bg="gray94")
self.label.grid(row=6, column=0, sticky='e')
self.text = Text(self, width=103, height=2, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=1, column=1, pady=(10, 5), sticky='w')
self.text = ScrolledText(self, width=103, height=2, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT,0)
self.text.grid(row=2, column=1, pady=(5), sticky='w')
self.text = Text(self, width=103, height=2, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=3, column=1, pady=(5), sticky='w')
self.text = Text(self, width=103, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT,0)
self.text.grid(row=4, column=1, pady=(5), sticky='w')
self.text = Text(self, width=103, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=5, column=1, pady=(5, 10), sticky='w')
self.text = ScrolledText(self, width=103, height=8, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT,0)
self.text.grid(row=6, column=1, pady=(5, 10))
class ImgFrame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, bg='gray94', borderwidth=0, relief=GROOVE)
self.parent = parent
self.widgets()
def widgets(self):
try:
self.Imgfile = "Logo_Tiger_tout_blanc.png"
self.img = PhotoImage(file=self.Imgfile)
self.img_2 = self.img.subsample(3, 3)
self.Image = Label(image=self.img_2, bg='gray94')
self.Image.grid(row=3, column=1, sticky='n')
except:
self.label = Label(self, text="title \n title title title", bg="gray94", font=("Calibri", 14))
self.label.grid(row=1, column=0, sticky='e', padx=5)
class CalibrationFrame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, bg="gray94", borderwidth=2, relief=GROOVE)
self.parent = parent
self.widgets()
def widgets(self):
self.label = Label(self, text="Freq adjustment :", bg="gray94")
self.label.grid(row=1, column=0, sticky='e')
self.label = Label(self, text="Avoided calibration :", bg="gray94")
self.label.grid(row=2, column=0, sticky='e')
self.text = Text(self, width=23, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=1, column=1, pady=(27, 28))
self.text = Text(self, width=23, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=2, column=1, pady=(28))
class StatFrame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, bg="gray94", borderwidth=2, relief=GROOVE)
self.parent = parent
self.widgets()
def widgets(self):
self.label = Label(self, text="Accepted :", bg="gray94")
self.label.grid(row=1, column=0, sticky='e', pady=(10, 0))
self.label = Label(self, text="Rejected :", bg="gray94")
self.label.grid(row=2, column=0, sticky='e')
self.label = Label(self, text="Reject rate :", bg="gray94")
self.label.grid(row=3, column=0, sticky='e')
self.label = Label(self, text="Pvalue :", bg="gray94")
self.label.grid(row=4, column=0, sticky='e', pady=(0, 10))
self.text = Text(self, width=25, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=1, column=1, pady=(19, 5))
self.text = Text(self, width=25, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=2, column=1, pady=(5))
self.text = Text(self, width=25, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=3, column=1, pady=(5))
self.text = Text(self, width=25, height=1, font=("Calibri", 11), wrap=WORD)
self.text.insert(INSERT, 0)
self.text.grid(row=4, column=1, pady=(5, 18))
class ButtonFrame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, bg="gray94")
self.parent = parent
self.widgets()
def widgets(self):
self.Border1 = LabelFrame(self, bd=2, bg="DodgerBlue3", relief=FLAT)
self.Border1.grid(row=1, pady=(5, 10), padx=(20, 20))
self.Border2 = LabelFrame(self, bd=2, bg="DodgerBlue3", relief=FLAT)
self.Border2.grid(row=2, pady=(10, 5))
self.button1 = Button(self.Border1, text='Save in \n Database', command=self.parent.destroy, relief='flat',
bg='gray90', border=0,
highlightcolor='blue', activebackground='SlateGray1')
self.button1.grid()
self.button2 = Button(self.Border2, text='Close', command=self.parent.destroy, relief='flat', bg='gray90',
border=0,
highlightcolor='blue', activebackground='SlateGray1')
self.button2.grid()
class MainW(Tk):
def __init__(self, parent):
Tk.__init__(self, parent)
self.parent = parent
self.mainWidgets()
self.title("title")
self['bg'] = 'gray94'
def mainWidgets(self):
self.label = Label(self, text="Sub-group :", bg='gray94')
self.label.grid(row=0, column=0, sticky='w', padx=7)
self.window = GroupFrame(self)
self.window.grid(row=1, column=0, columnspan=5, padx=5)
self.window = ImgFrame(self)
self.window.grid(row=3, column=1)
self.label = Label(self, text="Calibration :", bg='gray94')
self.label.grid(row=2, column=2, sticky='w')
self.window = CalibrationFrame(self)
self.window.grid(row=3, column=2, sticky='n')
self.label = Label(self, text="Statistics :", bg='gray94')
self.label.grid(row=2, column=3, sticky='w')
self.window = StatFrame(self)
self.window.grid(row=3, column=3, sticky='n')
self.window = ButtonFrame(self)
self.window.grid(row=3, column=0, padx=(2), rowspan=3)
self.label = Label(self, text="Response :", bg='gray94')
self.label.grid(row=4, column=1, sticky='w')
self.text = Text(self, width=74, height=3, font=("Calibri", 15), wrap=WORD)
self.text.insert(INSERT, 000)
self.text.grid(row=5, column=1, columnspan=5, pady=(0, 5), padx=(0, 5))
focus = 0
def focus_in(event):
global focus
focus += 1
def focus_out(event):
global focus
focus -= 1
if focus == 0:
app.destroy()
app = MainW(NONE)
app.focus_force()
app.bind("<FocusOut>", focus_out)
app.bind("<FocusIn>", focus_in)
app.mainloop()
解决方案
推荐阅读
- c - Julia 中的 C 结构类型对应关系
- java - 将精度浮点数丢失为整数
- python - 读取 Excel 宏
- haskell - 编译器如何确定函子的固定点以及 cata 如何在叶级工作?
- codeigniter - 如何在 Codeigniter 1 中更改管理员登录 url?
- javascript - 使用 OpenLayers 和 CSS 网格布局时如何正确设置对齐方式
- sql - 在 SQL 中正确显示下一个计费周期开始日期 - [应根据报表运行日期显示未来计费日期]
- rust - 嵌套循环打印奇怪的结果
- java - Android - 在单独的线程中从 for 循环更新进度条
- r - 如何合并数据库,将一个值重复到另一个值中?