我正在使用Python tkinter进行设计。在我的UI中,我有一个 画布,分隔符和滚动条。在更新时,新的画布 正在附加到前一个。你能告诉我如何删除 以前的画布,分隔符&滚动条?
我试过select dt.vendor,
dt.email,
dt.address,
c.country,
m.material,
c.country
from country c
inner join vendor_countries vc on (c.id = vc.cid)
right join details dt on (dt.id = vc.did)
left join vendor_materials vm on dt.id = vm.did
left join material m on vm.mid = m.id
,separator.destroy()
,
canvas.delete('all')
,self.canvas.delete('all')
等
CODE:
self.canvas.update_idletasks()
答案 0 :(得分:1)
为了清除框架的内容,我们的想法是摧毁它的所有孩子。框架的所有子项都存储在dictionnary frame.children
中(在{name:widget}下面)
children = list(frame.children.values())
for child in children:
child.destroy()
您可以使用它来清除分隔符2,3和2的内容。 6 get()
开头。 separator2
仅在get()
内部定义,与其他框架的定义不一致,这意味着每次运行separator2
时都会创建新的get()
。所以我把它移到了函数之外,还有其他框架。
以下是修改后的代码:
from tkinter import *
import matplotlib
import pandas as pd
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from matplotlib.figure import Figure
master = Tk()
separator3 = Frame(master, height=618,width=180, bd=4, bg='dodgerblue')
separator6 = Frame(master, height=250,width=240, bd=4, bg='dodgerblue')
separator1 = Frame(master, height=100,width=100, bd=1,bg='dodgerblue')
separator2 = Frame(master, height=150, width=280, bd=4, bg='dodgerblue') # define separator2 outside get()
def get():
# start by clearing frames
children = list(separator6.children.values()) + list(separator3.children.values()) + list(separator2.children.values())
for child in children:
child.destroy()
Disp_pos =10
Disp_neg =-12
w = Scale(separator6, from_=10, to=0,orient=VERTICAL)
w.set(Disp_pos)
w.pack(anchor=CENTER,side=TOP,ipady=10,ipadx=10)
Label1 = Label(separator6, text="")
Label1.pack(anchor=CENTER, side=TOP)
f3 = Figure(figsize=(2, 3), dpi=100)
canvas2 = FigureCanvasTkAgg(f3, master=separator3)
Label1 = Label(separator3,text=" WORD CLOUD ")
Label1.pack(anchor=CENTER, side=TOP)
ax3 = f3.add_subplot(111)
text = 'sample'
print(type(text))
ax3.set_wordcloud = WordCloud().generate(text)
ax3.imshow(ax3.set_wordcloud, interpolation='bilinear')
ax3.axis("off")
canvas2.show()
canvas2.get_tk_widget().pack( side=BOTTOM,fill=BOTH, expand=1)
canvas2.draw()
scrollbar = Scrollbar(separator2)
scrollbar.pack(side=RIGHT, ipady=270, fill=Y)
Label1 = Label(separator2, text=" TEXT ",font=('Times', 12))
Label1.pack(anchor=CENTER, side=TOP)
i = 'sample sample sample'
Re=Listbox(separator2,yscrollcommand=scrollbar.set)
Re.insert(END, i)
Re.pack()
scrollbar.config(command=Re.yview)
Button1 = Button(separator1, text=' GET ', font=('Times',
15,'bold'),command=get, bg="wheat2",relief=RAISED)
Button1.pack(anchor=CENTER,pady=5)
separator1.pack(fill=BOTH,side=LEFT, padx=5, pady=5)
separator6.pack(fill=BOTH,side=RIGHT, padx=5, pady=5)
separator3.pack(side=BOTTOM,fill=BOTH,padx=5, pady=5)
separator2.pack(side=TOP, padx=10, pady=10, fill=BOTH)
master.config(bg='white')
master.title('sample')
mainloop()