I have the following code:
(我有以下代码:)
import tkinter as tk
data = [['A',1],['B',2],['C',3],['D',4]]
def ranking():
root = tk.Tk()
root.focus_force()
windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)
root.geometry("+{}+{}".format(positionRight, positionDown))
for i in range(0,len(data)):
tk.Label(image=tk.PhotoImage(file="D:\A\" + data[i][0] + ".gif")).grid(row=data[i][1]-1, column=0)
root.mainloop()
ranking()
What I want to do is to have a random number of pictures (whatever is inserted in data at any moment), displayed within the window (in the order as indicated within the data), yet if I currently run the code it simply results in a blank window.The names of the pictures are literally A, B, C...and they display without a problem if I use something like (this is an extract from another piece of code I wrote):
(我想做的是在窗口内(按数据中指示的顺序)显示随机数量的图片(无论何时将其插入到数据中),但是如果我当前运行代码,它只会导致图片的名称实际上是A,B,C ...,如果我使用类似的图片,它们的显示就没有问题(这是我编写的另一段代码的摘录):)
img2 = tk.PhotoImage(file="D:\A\" + choice2 + ".gif")
label_img2 = tk.Label(image=img2)
label_img2.grid(row=2, column=1)
Any guidance would be very welcome as I am still quite new with working with tkinter!
(任何指导都将受到欢迎,因为与tkinter合作对我来说还很新!)
ask by Noir translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…