如何使用if语句将图像添加到GUI中

时间:2017-10-19 19:22:26

标签: python python-3.x tkinter python-3.6

使用tkinter,我想在GUI代码中添加if语句,如果某个名称被选中(随机),我想显示所选人员的图像。例如,如果在挑选防御者时选择Valkyrie,我想要她的名字和这张照片

enter image description here

出现。继承我的GUI代码:

from tkinter import *
import tkinter
import tkinter as tk
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():
    nameLabel.configure(text=random.choice(names))
def pickName1():
    nameLabel.configure(text=random.choice(name))



root.title("Operator Picker")

root.geometry("1920x300")

nameLabel = tkinter.Label(root, text="", font=('Helvetica', 32))
nameLabel.pack()
Grid()

pickButton1 = tkinter.Button(root, text="Pick Attack", command=pickName, 
height=100, width=100)
pickButton1.pack(side=tkinter.LEFT)
pickButton2 = tkinter.Button(root, text="Pick Defend", command=pickName1, 
height=100, width=100)
pickButton2.pack(side=tkinter.RIGHT)

root.mainloop()

我尝试使用if语句,但是没有变量我可以附加它。所有帮助表示赞赏,谢谢!

0 个答案:

没有答案