【发布时间】:2017-10-24 23:46:42
【问题描述】:
我一直在为《彩虹六号:围攻》编写一个随机操作员姓名生成器,我希望在他们的名字出现时出现操作员图片。图像看起来很好,但它不会消失。这是我的代码:
from tkinter import *
import tkinter
import random
names = ['Sledge','Thatcher','Ash','Thermite','Twitch','Montagne','Glaz','Fuze','Blitz','IQ','Buck','Blackbeard','Capitão','Hibana']
name = ["Smoke","Mute","Castle","Pulse","Doc","Rook","Kapkan","Tachanka","Jäger","Bandit","Frost","Valkyrie","Caveira","Echo"]
root = tkinter.Tk()
def pickName():
rad = random.choice(names)
photo = PhotoImage(file=rad+".png")
label = Label(image=photo)
label.image = photo # keep a reference!
label.pack()
nameLabel.configure(text=rad, foreground="white", background="blue")
root.configure(background='blue')
def pickName1(): nameLabel.configure(text=random.choice(name),background="orange",foreground="black")
root.configure(background='orange')
root.title("Operator Picker")
root.geometry("250x100")
nameLabel = tkinter.Label(root, text="", font=('Helvetica', 32))
nameLabel.pack()
Grid()
f1 = tkinter.Frame(root, height=100, width=100) #defines frame size in
pixels
f1.pack(side=tkinter.LEFT) #packs on the left
f1.pack_propagate(0) #tells frame not to let children control size
pickButton1 = tkinter.Button(f1, command=pickName, text="Pick
Attack",background="blue",foreground="white")
pickButton1.pack(fill=tkinter.BOTH, expand=1) #takes up all available space
f2 = tkinter.Frame(root, height=100, width=100)
f2.pack(side=tkinter.RIGHT)
f2.pack_propagate(0)
pickButton2 = tkinter.Button(f2, command=pickName1, text="Pick
Defend",background="orange",foreground="black")
pickButton2.pack(fill=tkinter.BOTH, expand=1)
root.mainloop()
注意:这仍然是一个 WIP,我所需要的只是知道如何在图片出现后将其删除。这是出现多张图片时的样子:https://imgur.com/eroXLLn
【问题讨论】:
-
我看不到任何地方你甚至试图让旧的小部件消失。你不会破坏它,也不会隐藏它。
-
@BryanOakley 我认为他不知道该怎么做。
-
@BryanOakley 是的,我不知道如何销毁它,这是我的问题
-
@Nae 可能,但我对如何在我的程序中实现它太缺乏经验
标签: python python-3.x tkinter tk python-3.6