如何使用tkinter全屏显示框架? (蟒蛇)

时间:2019-03-27 15:48:06

标签: python tkinter

我正在使用Tkinter进行gui实验,我在将带有一些标签的框架传递到全屏时遇到了一些困难,您有任何想法该怎么做吗?

#window 
root = Tk()
root.title("Sequencia")
#root.attributes('-fullscreen', True)
#root.bind('<Escape>',lambda e: root.destroy())
#root.state('zoomed')
#root.configure(background='black')
fm = Frame(root, width=500, height=350, bg="black")



# w = Canvas(fm, width=20, height=20, bg ="black", selectborderwidth=0)
#w.create_line(0, 200, 150, 150, width=10, fill="blue")

label_sim = Label(fm, width=10, height=1, bg="gray", text = "SIM")
label_nao = Label(fm, width=10, height=1, bg="gray", text = "NÃO")
label_fome = Label(fm, width=10, height=1, bg="gray", text = "FOME")
label_sede = Label(fm, width=10, height=1, bg="gray", text = "SEDE")
label_urinar = Label(fm, width=10, height=1, bg="gray", text = "URINAR")
label_ar = Label(fm, width=10, height=1, bg="gray", text = "AR")
label_posicao = Label(fm, width=10, height=1, bg="gray", text = "POSIÇÃO")



labels = [label_sim,label_nao,label_fome,label_sede,label_urinar,label_ar,label_posicao]

# ordem de sequencia (1 2 3 4 5 6 7): (SIM, NAO, FOME, SEDE, URINAR, AR, POSICAO)
fm.pack()
label_sim.place(relx=0.2, rely=0.5, anchor=CENTER)
label_nao.place(relx=0.8, rely=0.5, anchor=CENTER)
label_fome.place(relx=0.35, rely=0.8, anchor=CENTER)
label_sede.place(relx=0.65, rely=0.8, anchor=CENTER)
label_urinar.place(relx=0.25, rely=0.25, anchor=CENTER)
label_ar.place(relx=0.5, rely=0.1, anchor=CENTER)
label_posicao.place(relx=0.75, rely=0.25, anchor=CENTER)

root.update()

非常感谢你 编辑:我正在尝试的是自动使我具有全屏的框架,还是只有窗口可以?我们必须手动选择框架的大小吗?

EDIT2:我设法通过获取窗口的大小并放入框架的参数来实现:

#window 
root = Tk()
root.title("Sequencia")
root.attributes('-fullscreen', True)
root.bind('<Escape>',lambda e: root.destroy())
#root.state('zoomed')
#root.configure(background='black')
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
fm = Frame(root, width=w, height=h, bg="black")

1 个答案:

答案 0 :(得分:0)

这可能不是正确的答案,但是我会这样!

增大框架heightwidth,始终使用应用程序zoomed,最后使用resizable(0,0)删除(禁用)调整大小选项< / p>

import tkinter as tk


#window
root = tk.Tk()
root.title("Sequencia")
#root.attributes('-fullscreen', True)
#root.bind('<Escape>',lambda e: root.destroy())
#root.state('zoomed')
#root.configure(background='black')
fm = tk.Frame(root, width=1400, height=720, bg="black")




# w = Canvas(fm, width=20, height=20, bg ="black", selectborderwidth=0)
#w.create_line(0, 200, 150, 150, width=10, fill="blue")

label_sim = tk.Label(fm, width=10, height=1, bg="gray", text = "SIM")
label_nao = tk.Label(fm, width=10, height=1, bg="gray", text = "NÃO")
label_fome = tk.Label(fm, width=10, height=1, bg="gray", text = "FOME")
label_sede = tk.Label(fm, width=10, height=1, bg="gray", text = "SEDE")
label_urinar = tk.Label(fm, width=10, height=1, bg="gray", text = "URINAR")
label_ar = tk.Label(fm, width=10, height=1, bg="gray", text = "AR")
label_posicao = tk.Label(fm, width=10, height=1, bg="gray", text = "POSIÇÃO")



labels = [label_sim,label_nao,label_fome,label_sede,label_urinar,label_ar,label_posicao]

# ordem de sequencia (1 2 3 4 5 6 7): (SIM, NAO, FOME, SEDE, URINAR, AR, POSICAO)
fm.pack()
label_sim.place(relx=0.2, rely=0.5, anchor=tk.CENTER)
label_nao.place(relx=0.8, rely=0.5, anchor=tk.CENTER)
label_fome.place(relx=0.35, rely=0.8, anchor=tk.CENTER)
label_sede.place(relx=0.65, rely=0.8, anchor=tk.CENTER)
label_urinar.place(relx=0.25, rely=0.25, anchor=tk.CENTER)
label_ar.place(relx=0.5, rely=0.1, anchor=tk.CENTER)
label_posicao.place(relx=0.75, rely=0.25, anchor=tk.CENTER)

root.update()
root.state('zoomed')
root.resizable(0,0)
root.mainloop()