【发布时间】:2019-10-24 10:00:23
【问题描述】:
我正在尝试使用 if 语句创建一个更改动画演示文稿中幻灯片的功能,但是当幻灯片应该更改时,现有的小部件会保留。这是我的最小可复制示例(顺便说一下,“description.insert”在我的计算机上的格式正确,但在我的手机上却没有):
from tkinter import *
import random
import time
tk = Tk()
canvas = Canvas(tk, width = 400, height = 400)
tk.title('Diffusion')
canvas.pack()
slide = 0
def changeSlide():
global slide
slide += 1
#WRITE TEXT
if slide == 1:
description = Text(tk, bd=0, height=5, width = 50)
description.insert(INSERT, 'Diffusion is the net movement of particles from an area of higher concentration to an area of lower concentration, which results in the concentration being even. Here is an example, with the particles represented by orange dots:')
description.place(x=0, y=190)
elif slide == 2:
#DRAW PARTICLES
particle = canvas.create_oval(10, 10, 20, 20, fill = 'orange')
nexT = Button(tk, text = 'NEXT', command = changeSlide)
nexT.pack()
nexT.place(bordermode = 'inside', x = 350, y = 375)
【问题讨论】:
-
“现有的小部件保持不变”:在创建新小部件之前,您必须
.destroy()现有的小部件。 -
@stovfl 它适用于文本,但是当我尝试摧毁它
-
@stovfl 没关系...我解决了。不过感谢您的帮助!
标签: python function if-statement button tkinter