创建一个自动最大化的 tkinter 窗口
有两种不同的方法可以在 Tkinter 中获得一个自动最大化的窗口。
- 我们可以使用 Tkinter 的 state() 方法,并使用属性 “zoomed” 调用它。
root.state("zoomed")- 第二种方法是使用 Tkinter 的 attributes 方法,参数为 “-fullscreen”,并将其设置为 True。
默认情况下,Tkinter 创建了一个预定义大小的窗口。可以使用 geometry 方法来定制窗口的尺寸。例如:
root.geometry("700 x 350")
示例 1
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
root=Tk()
# Create a label
Label(root, text="Welcome to Tutorialspoint", font="Calibri, 20").pack(pady=20)
# Maximize the window Size using state property
root.state('zoomed')
root.mainloop()输出
它将产生以下输出 -
示例 2
现在,我们修改一下代码,使用 attribute 方法代替 state 方法。
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
root=Tk()
# Create a label
Label(root, text="Welcome to Tutorialspoint", font="Calibri, 20").pack(pady=20)
# Maximize the window Size using attributes method
root.attributes('-fullscreen', True)
root.mainloop()输出
它将产生以下输出 -
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP