在 Tkinter Python 中的第一次迭代后,销毁函数没有有效地销毁帧 [英] Destroy function not destroying a frame efficiently after the first iteration in Tkinter Python

查看:36
本文介绍了在 Tkinter Python 中的第一次迭代后,销毁函数没有有效地销毁帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个代码,用于在 for 循环中的每次迭代中保存计算数据,并将结果存储在 3 个不同的 csv 文件中.这些保存的结果在另一个 python 代码中读取,该代码使用 GUI tkinter 在包含三个不同框架的窗口上显示结果.这三帧完美地每 3 秒更新一次.

我在三个框架中的每一个上都添加了一个关闭"按钮,按下该按钮时应仅销毁/关闭特定框架.在第一次迭代中,当我在三个框架中的任何一个上按下关闭按钮时,框架的破坏/关闭都完成了.但是,随着时间的推移,当超过 1 次迭代完成时,关闭按钮不会立即关闭.

例如,假设已经完成了 3 次迭代和计算,所以当我按下关闭按钮时,它会在第四次按下时关闭,在按下它之前,帧将显示之前显示的 PREVIOUS 结果迭代.. 如何编辑?我在下面附上了我的代码.

<预><代码>随机导入从 tkinter 进口*将 tkinter 作为 tk 导入导入 csv将 numpy 导入为 np导入时间基数 = tk.Tk()base.geometry("500x300")frame1 = tk.LabelFrame(base, text="MVs ", width=240, height=330, bd=15)frame2 = tk.LabelFrame(base, text="CVs ", width=240, height=330, bd=15)frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)定义 MVs():#从保存的Excel表格中读取文件MV=np.empty(8)使用 open("MVs.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型MV[count]=i #更新y数组count +=1 # 递增 1 得到总数MV=MV.reshape(8,1)frame1 = tk.LabelFrame(base, text="MVs", width=240, height=330, bd=15)frame1.grid(row=1, column=0, padx=8)#显示行标题def exit_btn():frame1.destroy()#frame1.update()btn1_c=Button(frame1,text="Close",command=exit_btn).grid(column=1,columnspan=1,row=10,rowspan=1,sticky=W)标签(frame1,text="Tc Measured").grid(column=0,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame1,text="Tc Optimum").grid(column=0,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame1,text="Tc Cost").grid(column=0,columnspan=1,row=4,rowspan=1,sticky=W)标签(frame1,text="Tc Weight").grid(column=0,columnspan=1,row=5,rowspan=1,sticky=W)标签(frame1,text="Q Measured").grid(column=0,columnspan=1,row=6,rowspan=1,sticky=W)标签(frame1,text="Q Optimum").grid(column=0,columnspan=1,row=7,rowspan=1,sticky=W)标签(frame1,text="Q Cost").grid(column=0,columnspan=1,row=8,rowspan=1,sticky=W)标签(frame1,text="Q Weight").grid(column=0,columnspan=1,row=9,rowspan=1,sticky=W)对于范围内的 i (8):标签(frame1,text= str(round(MV[i,0],5))).grid(column=1,columnspan=1,row=i+2,rowspan=1,sticky=W)定义简历():CV=np.empty(8)使用 open("CVs.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型CV[count]=i #更新y数组count +=1 # 递增 1 得到总数CV=CV.reshape(8,1)frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)frame2.grid(row=1, column=3, padx=8)def exit_btn():frame2.destroy()# frame2.update()#显示行标题btn2_c=Button(frame2,text="Close",command=exit_btn).grid(column=3,columnspan=1,row=10,rowspan=1,sticky=W)标签(frame2,text="T Measured").grid(column=3,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame2,text="T Optimum").grid(column=3,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame2,text="T Revenue").grid(column=3,columnspan=1,row=4,rowspan=1,sticky=W)标签(frame2,text="T Weight").grid(column=3,columnspan=1,row=5,rowspan=1,sticky=W)标签(frame2,text="Ca Measured").grid(column=3,columnspan=1,row=6,rowspan=1,sticky=W)标签(frame2,text="Ca Optimum").grid(column=3,columnspan=1,row=7,rowspan=1,sticky=W)标签(frame2,text="Ca Revenue").grid(column=3,columnspan=1,row=8,rowspan=1,sticky=W)标签(frame2,text="Ca Weight").grid(column=3,columnspan=1,row=9,rowspan=1,sticky=W)对于范围内的 i (8):标签(frame2,text= str(round(CV[i,0],5))).grid(column=4,columnspan=1,row=i+2,rowspan=1,sticky=W)def DVs():dist=np.empty(1)使用 open("disturbance.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型dist[count]=i #更新y数组count +=1 # 递增 1 得到总数dist=dist.reshape(1,1)frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)frame3.grid(row=1, column=5, padx=8)def exit_btn():frame3.destroy()# frame3.update()btn3_c=Button(frame3,text="Close",command=exit_btn).grid(column=5,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame3,text="Q Loss").grid(column=5,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame3,text= str(round(dist[0,0],3))).grid(column=6,columnspan=1,row=2,rowspan=1,sticky=W)btn1=Button(base,text='MVs',command=MVs)btn2=Button(base,text='CVs',command=CVs)btn3=Button(base,text='DVs',command=DVs)btn1.grid(row=0,column=0)btn2.grid(row=0,column=3)btn3.grid(row=0,column=5)我=0显示=真#显示结果而(显示==真):#base.after(i, MVs) #in msframe1.after(i, MV)#frame1.after(i+100,frame1.destroy)#base.after(i, CVs) #in msframe2.after(i, CVs)#frame2.after(i+100,frame2.destroy)#base.after(i, DVs) #in msframe3.after(i, DVs)#frame3.after(i+100,frame3.destroy)base.update()#更新显示我=我+3000base.mainloop()

解决方案

我找到了解决这个问题的方法.然而,一个新的问题出现了..

基本上,我在 MVs 函数中定义了 frame1.我删除了它并只在开始时保留它.对 frame2 和 frame3 进行了相同的方法.这样,当我按下关闭按钮时,相应的框架会立即关闭.但是,现在当我关闭 frame1 时,例如,当我再次按下 MVs 按钮时,frame1 不会再次打开.它给了我一个错误:

_tkinter.TclError: bad window path name ".!labelframe"

如果我不按下关闭按钮,这个问题就不会发生.因此,问题肯定出在破坏和关闭框架上.

我在这里附上了我编辑过的代码:

随机导入从 tkinter 进口*将 tkinter 作为 tk 导入导入 csv将 numpy 导入为 np导入时间基数 = tk.Tk()base.geometry("500x300")frame1 = tk.LabelFrame(base, text="MVs ", width=240, height=330, bd=15)frame1.grid(row=1, column=0, padx=8)frame2 = tk.LabelFrame(base, text="CVs ", width=240, height=330, bd=15)frame2.grid(row=1, column=3, padx=8)frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)frame3.grid(row=1, column=5, padx=8)z=假定义 MVs():#从保存的Excel表格中读取文件全局 z全局框架1如果 z==真:frame1 = tk.LabelFrame(base, text="MVs", width=240, height=330, bd=15)frame1.grid(row=1, column=0, padx=8)MV=np.empty(8)使用 open("MVs.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型MV[count]=i #更新y数组count +=1 # 递增 1 得到总数MV=MV.reshape(8,1)#显示行标题def exit_btn():z=真frame1.destroy()frame1.update()如果 z==False:标签(frame1,text="Tc Measured").grid(column=0,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame1,text="Tc Optimum").grid(column=0,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame1,text="Tc Cost").grid(column=0,columnspan=1,row=4,rowspan=1,sticky=W)标签(frame1,text="Tc Weight").grid(column=0,columnspan=1,row=5,rowspan=1,sticky=W)标签(frame1,text="Q Measured").grid(column=0,columnspan=1,row=6,rowspan=1,sticky=W)标签(frame1,text="Q Optimum").grid(column=0,columnspan=1,row=7,rowspan=1,sticky=W)标签(frame1,text="Q Cost").grid(column=0,columnspan=1,row=8,rowspan=1,sticky=W)标签(frame1,text="Q Weight").grid(column=0,columnspan=1,row=9,rowspan=1,sticky=W)对于范围内的 i (8):标签(frame1,text= str(round(MV[i,0],5))).grid(column=1,columnspan=1,row=i+2,rowspan=1,sticky=W)btn1_c=Button(frame1,text="Close",command=exit_btn).grid(column=1,columnspan=1,row=10,rowspan=1,sticky=W)定义简历():全局 z全局框架2如果 z==真:frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)frame2.grid(row=1, column=3, padx=8)CV=np.empty(8)使用 open("CVs.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型CV[count]=i #更新y数组count +=1 # 递增 1 得到总数CV=CV.reshape(8,1)#frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)#frame2.grid(row=1, column=3, padx=8)def exit_btn():z=真frame2.destroy()frame2.update()#显示行标题标签(frame2,text="T Measured").grid(column=3,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame2,text="T Optimum").grid(column=3,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame2,text="T Revenue").grid(column=3,columnspan=1,row=4,rowspan=1,sticky=W)标签(frame2,text="T Weight").grid(column=3,columnspan=1,row=5,rowspan=1,sticky=W)标签(frame2,text="Ca Measured").grid(column=3,columnspan=1,row=6,rowspan=1,sticky=W)标签(frame2,text="Ca Optimum").grid(column=3,columnspan=1,row=7,rowspan=1,sticky=W)标签(frame2,text="Ca Revenue").grid(column=3,columnspan=1,row=8,rowspan=1,sticky=W)标签(frame2,text="Ca Weight").grid(column=3,columnspan=1,row=9,rowspan=1,sticky=W)对于范围内的 i (8):标签(frame2,text= str(round(CV[i,0],5))).grid(column=4,columnspan=1,row=i+2,rowspan=1,sticky=W)btn2_c=Button(frame2,text="Close",command=exit_btn).grid(column=3,columnspan=1,row=10,rowspan=1,sticky=W)def DVs():dist=np.empty(1)使用 open("disturbance.csv","r") 作为 csv_file:计数=0csv_reader=csv.reader(csv_file)对于 csv_reader 中的行:i=row[0]#从字符串改为浮点类型dist[count]=i #更新y数组count +=1 # 递增 1 得到总数dist=dist.reshape(1,1)#frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)#frame3.grid(row=1, column=5, padx=8)def exit_btn():frame3.destroy()frame3.update()btn3_c=Button(frame3,text="Close",command=exit_btn).grid(column=5,columnspan=1,row=3,rowspan=1,sticky=W)标签(frame3,text="Q Loss").grid(column=5,columnspan=1,row=2,rowspan=1,sticky=W)标签(frame3,text= str(round(dist[0,0],3))).grid(column=6,columnspan=1,row=2,rowspan=1,sticky=W)btn1=Button(base,text='MVs',command=MVs)btn2=Button(base,text='CVs',command=CVs)btn3=Button(base,text='DVs',command=DVs)btn1.grid(row=0,column=0)btn2.grid(row=0,column=3)btn3.grid(row=0,column=5)我=0显示=真#显示结果而(显示==真):#base.after(i, MVs) #in msframe1.after(i, MV)#frame1.after(i+100,frame1.destroy)#base.after(i, CVs) #in msframe2.after(i, CVs)#frame2.after(i+100,frame2.destroy)#base.after(i, DVs) #in msframe3.after(i, DVs)#frame3.after(i+100,frame3.destroy)base.update()#更新显示我=我+3000base.mainloop()

I have built a code that saves the calculated data at every iteration in a for loop and the results are stored in 3 different csv files. These saved results are read in another python code that displays the results using GUI tkinter on a window containing three different frames. These three frames are updated every 3 seconds perfectly.

I added a "close" button on each of the three frames that when pressed should DESTROY/CLOSE the specific frame only. At the first iteration and when I press the close button on any of the three frames, the destruction / closure of the frame is done perfectly. However, when time moves on and when more than 1 iteration is done, the close button doesn't close immediately.

For instance, say that 3 iterations and calculations have been done, so when I press the close button it will close on the FOURTH press and before that when it is pressed the frames will show the PREVIOUS results that were shown in the previous iteration .. How can that be edited ? I have attached my code below.


import random
from tkinter import*
import tkinter as tk
import csv
import numpy as np
import time
base = tk.Tk()
base.geometry("500x300")

frame1 = tk.LabelFrame(base, text="MVs ", width=240, height=330, bd=15)
frame2 = tk.LabelFrame(base, text="CVs ", width=240, height=330, bd=15)
frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)

def MVs():
    #read files from saved excel sheets

    MV=np.empty(8)

    with open("MVs.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            MV[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        MV=MV.reshape(8,1)


    frame1 = tk.LabelFrame(base, text="MVs", width=240, height=330, bd=15)


    frame1.grid(row=1, column=0,  padx=8)

    #Display row titles
    def exit_btn():

        frame1.destroy()
        #frame1.update()

    btn1_c=Button(frame1,text="Close",command=exit_btn).grid(column=1,columnspan=1,row=10,rowspan=1, sticky=W)    
    Label(frame1,text="Tc Measured").grid(column=0,columnspan=1,row=2,rowspan=1, sticky=W)
    Label(frame1,text="Tc Optimum").grid(column=0,columnspan=1,row=3,rowspan=1, sticky=W)
    Label(frame1,text="Tc Cost").grid(column=0,columnspan=1,row=4,rowspan=1, sticky=W)
    Label(frame1,text="Tc Weight").grid(column=0,columnspan=1,row=5,rowspan=1, sticky=W)

    Label(frame1,text="Q Measured").grid(column=0,columnspan=1,row=6,rowspan=1, sticky=W)
    Label(frame1,text="Q Optimum").grid(column=0,columnspan=1,row=7,rowspan=1, sticky=W)
    Label(frame1,text="Q Cost").grid(column=0,columnspan=1,row=8,rowspan=1, sticky=W)
    Label(frame1,text="Q Weight").grid(column=0,columnspan=1,row=9,rowspan=1, sticky=W)

    for i in range(8):
        Label(frame1,text= str(round(MV[i,0],5))).grid(column=1 ,columnspan=1,row=i+2,rowspan=1, sticky=W)


def CVs():

    CV=np.empty(8)

    with open("CVs.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            CV[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        CV=CV.reshape(8,1)

    frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)

    frame2.grid(row=1, column=3,  padx=8)

    def exit_btn():

        frame2.destroy()
       # frame2.update()

    #Display row titles
    btn2_c=Button(frame2,text="Close",command=exit_btn).grid(column=3,columnspan=1,row=10,rowspan=1, sticky=W)    
    Label(frame2,text="T Measured").grid(column=3,columnspan=1,row=2,rowspan=1, sticky=W)
    Label(frame2,text="T Optimum").grid(column=3,columnspan=1,row=3,rowspan=1, sticky=W)
    Label(frame2,text="T Revenue").grid(column=3,columnspan=1,row=4,rowspan=1, sticky=W)
    Label(frame2,text="T Weight").grid(column=3,columnspan=1,row=5,rowspan=1, sticky=W)

    Label(frame2,text="Ca Measured").grid(column=3,columnspan=1,row=6,rowspan=1, sticky=W)
    Label(frame2,text="Ca Optimum").grid(column=3,columnspan=1,row=7,rowspan=1, sticky=W)
    Label(frame2,text="Ca Revenue").grid(column=3,columnspan=1,row=8,rowspan=1, sticky=W)
    Label(frame2,text="Ca Weight").grid(column=3,columnspan=1,row=9,rowspan=1, sticky=W)

    for i in range(8):
        Label(frame2,text= str(round(CV[i,0],5))).grid(column=4 ,columnspan=1,row=i+2,rowspan=1, sticky=W)

def DVs():

    dist=np.empty(1)

    with open("disturbance.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            dist[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        dist=dist.reshape(1,1)

    frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)

    frame3.grid(row=1, column=5,  padx=8)

    def exit_btn():

        frame3.destroy()
       # frame3.update()

    btn3_c=Button(frame3,text="Close",command=exit_btn).grid(column=5,columnspan=1,row=3,rowspan=1, sticky=W)    
    Label(frame3,text="Q Loss").grid(column=5,columnspan=1,row=2,rowspan=1, sticky=W)
    Label(frame3,text= str(round(dist[0,0],3))).grid(column=6 ,columnspan=1,row=2,rowspan=1, sticky=W)


btn1=Button(base,text='MVs',command=MVs)
btn2=Button(base,text='CVs',command=CVs)
btn3=Button(base,text='DVs',command=DVs)

btn1.grid(row=0,column=0)
btn2.grid(row=0,column=3)
btn3.grid(row=0,column=5)


i=0
show=True
#show results

while(show==True):

    #base.after(i, MVs) #in ms
    frame1.after(i, MVs)
    #frame1.after(i+100,frame1.destroy)
    #base.after(i, CVs) #in ms
    frame2.after(i, CVs)
    #frame2.after(i+100,frame2.destroy)
    #base.after(i, DVs) #in ms
    frame3.after(i, DVs)
    #frame3.after(i+100,frame3.destroy)

    base.update()#update display

    i=i+3000

base.mainloop()

解决方案

I found a way that solves this problem. However, a new problem arises ..

Basically, I was defining frame1 inside the MVs function. I removed that and kept it only at the beginning. The same approach was done for frame2 and frame3. This way, when I press the close button, the respective frame is immediately closed. However, now when I have closed frame1 for instance, when I press the MVs button again, the frame1 is NOT opening again. It is giving me an error:

_tkinter.TclError: bad window path name ".!labelframe"

If I don't press the close button, this problem does not happen. Hence, the problem is definitely from destroying and closing the frames.

I have attached my edited code here:

import random
from tkinter import*
import tkinter as tk
import csv
import numpy as np
import time
base = tk.Tk()
base.geometry("500x300")



frame1 = tk.LabelFrame(base, text="MVs ", width=240, height=330, bd=15)
frame1.grid(row=1, column=0,  padx=8)


frame2 = tk.LabelFrame(base, text="CVs ", width=240, height=330, bd=15)
frame2.grid(row=1, column=3,  padx=8)

frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)
frame3.grid(row=1, column=5,  padx=8)


z=False

def MVs():
    #read files from saved excel sheets

    global z
    global frame1

    if z==True:

        frame1 = tk.LabelFrame(base, text="MVs", width=240, height=330, bd=15)

        frame1.grid(row=1, column=0,  padx=8)

    MV=np.empty(8)

    with open("MVs.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            MV[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        MV=MV.reshape(8,1)


    #Display row titles
    def exit_btn():

        z=True
        frame1.destroy()
        frame1.update()

    if z==False:

        Label(frame1,text="Tc Measured").grid(column=0,columnspan=1,row=2,rowspan=1, sticky=W)
        Label(frame1,text="Tc Optimum").grid(column=0,columnspan=1,row=3,rowspan=1, sticky=W)
        Label(frame1,text="Tc Cost").grid(column=0,columnspan=1,row=4,rowspan=1, sticky=W)
        Label(frame1,text="Tc Weight").grid(column=0,columnspan=1,row=5,rowspan=1, sticky=W)

        Label(frame1,text="Q Measured").grid(column=0,columnspan=1,row=6,rowspan=1, sticky=W)
        Label(frame1,text="Q Optimum").grid(column=0,columnspan=1,row=7,rowspan=1, sticky=W)
        Label(frame1,text="Q Cost").grid(column=0,columnspan=1,row=8,rowspan=1, sticky=W)
        Label(frame1,text="Q Weight").grid(column=0,columnspan=1,row=9,rowspan=1, sticky=W)

        for i in range(8):
            Label(frame1,text= str(round(MV[i,0],5))).grid(column=1 ,columnspan=1,row=i+2,rowspan=1, sticky=W)

        btn1_c=Button(frame1,text="Close",command=exit_btn).grid(column=1,columnspan=1,row=10,rowspan=1, sticky=W)

def CVs():

    global z
    global frame2

    if z==True:

        frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)

        frame2.grid(row=1, column=3,  padx=8)

    CV=np.empty(8)

    with open("CVs.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            CV[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        CV=CV.reshape(8,1)

    #frame2 = tk.LabelFrame(base, text="CVs", width=240, height=330, bd=15)

    #frame2.grid(row=1, column=3,  padx=8)

    def exit_btn():

        z=True
        frame2.destroy()
        frame2.update()

    #Display row titles

    Label(frame2,text="T Measured").grid(column=3,columnspan=1,row=2,rowspan=1, sticky=W)
    Label(frame2,text="T Optimum").grid(column=3,columnspan=1,row=3,rowspan=1, sticky=W)
    Label(frame2,text="T Revenue").grid(column=3,columnspan=1,row=4,rowspan=1, sticky=W)
    Label(frame2,text="T Weight").grid(column=3,columnspan=1,row=5,rowspan=1, sticky=W)

    Label(frame2,text="Ca Measured").grid(column=3,columnspan=1,row=6,rowspan=1, sticky=W)
    Label(frame2,text="Ca Optimum").grid(column=3,columnspan=1,row=7,rowspan=1, sticky=W)
    Label(frame2,text="Ca Revenue").grid(column=3,columnspan=1,row=8,rowspan=1, sticky=W)
    Label(frame2,text="Ca Weight").grid(column=3,columnspan=1,row=9,rowspan=1, sticky=W)

    for i in range(8):
        Label(frame2,text= str(round(CV[i,0],5))).grid(column=4 ,columnspan=1,row=i+2,rowspan=1, sticky=W)

    btn2_c=Button(frame2,text="Close",command=exit_btn).grid(column=3,columnspan=1,row=10,rowspan=1, sticky=W)   

def DVs():

    dist=np.empty(1)

    with open("disturbance.csv","r") as csv_file:

        count=0

        csv_reader=csv.reader(csv_file)
        for row in csv_reader:
            i=row[0]#change from string to float type
            dist[count]=i #update y array
            count +=1 # increment of 1 to get the number of total values

        dist=dist.reshape(1,1)

    #frame3 = tk.LabelFrame(base, text="DVs ", width=240, height=330, bd=15)

    #frame3.grid(row=1, column=5,  padx=8)

    def exit_btn():

        frame3.destroy()
        frame3.update()

    btn3_c=Button(frame3,text="Close",command=exit_btn).grid(column=5,columnspan=1,row=3,rowspan=1, sticky=W)    
    Label(frame3,text="Q Loss").grid(column=5,columnspan=1,row=2,rowspan=1, sticky=W)
    Label(frame3,text= str(round(dist[0,0],3))).grid(column=6 ,columnspan=1,row=2,rowspan=1, sticky=W)


btn1=Button(base,text='MVs',command=MVs)
btn2=Button(base,text='CVs',command=CVs)
btn3=Button(base,text='DVs',command=DVs)

btn1.grid(row=0,column=0)
btn2.grid(row=0,column=3)
btn3.grid(row=0,column=5)


i=0
show=True
#show results

while(show==True):

    #base.after(i, MVs) #in ms
    frame1.after(i, MVs)
    #frame1.after(i+100,frame1.destroy)
    #base.after(i, CVs) #in ms
    frame2.after(i, CVs)
    #frame2.after(i+100,frame2.destroy)
    #base.after(i, DVs) #in ms
    frame3.after(i, DVs)
    #frame3.after(i+100,frame3.destroy)

    base.update()#update display

    i=i+3000

base.mainloop()

这篇关于在 Tkinter Python 中的第一次迭代后,销毁函数没有有效地销毁帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆