简体   繁体   English

全屏 tkinter canvas python

[英]Full screen tkinter canvas python

Hello how can I make a full screen tkinter.Canvas ?您好,如何制作全屏tkinter.Canvas Can you help me?你能帮助我吗? This is my code:这是我的代码:

import tkinter
import datetime
import sys
import os

uvodcanvas = tkinter.Canvas(width=400,height=200,bg="white")
uvodcanvas.pack()

tkinter.mainloop()

You need to make your main window full-screen, then configure the canvas to occupy the whole main window:你需要让你的主window全屏,然后配置canvas占据整个主window:

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()

You can set root.attributes to fullscreen.您可以将root.attributes设置为全屏。
The following example shows how to toggle from fullscreen to a sized window, and vice-versa, upon pressing the Escape key以下示例显示了如何在按Escape键时从全屏切换到大小的 window,反之亦然

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM