【问题标题】:Full screen tkinter canvas python全屏tkinter画布python
【发布时间】:2020-06-01 10:51:51
【问题描述】:
你好,我怎样才能全屏tkinter.Canvas?你能帮助我吗?这是我的代码:
import tkinter
import datetime
import sys
import os
uvodcanvas = tkinter.Canvas(width=400,height=200,bg="white")
uvodcanvas.pack()
tkinter.mainloop()
【问题讨论】:
标签:
python
tkinter
fullscreen
tkinter-canvas
【解决方案1】:
你需要让你的主窗口全屏,然后配置画布占据整个主窗口:
import tkinter as tk
root = tk.Tk()
root.attributes('-fullscreen', True) # make main window full-screen
canvas = tk.Canvas(root, bg='white', highlightthickness=0)
canvas.pack(fill=tk.BOTH, expand=True) # configure canvas to occupy the whole main window
root.mainloop()
【解决方案2】:
您可以将root.attributes 设置为全屏。
以下示例显示了如何在按下 Escape 键时从全屏切换到大小窗口,反之亦然
import tkinter as tk
def toggle_fs(dummy=None):
state = False if root.attributes('-fullscreen') else True
root.attributes('-fullscreen', state)
if not state:
root.geometry('300x300+100+100')
root = tk.Tk()
tk.Canvas(root, bg='cyan').pack(expand=True, fill=tk.BOTH)
root.attributes('-fullscreen', True)
root.bind('<Escape>', toggle_fs)
root.mainloop()