如何在 macOS 上以全屏显示 tkinter 应用程序?
Tkinter 是一个 Python GUI 工具包,广泛用于开发功能齐全的桌面应用程序。Tkinter 提供了许多内置库、部件和模块来开发任何类型的应用程序。您可以使用工厂和类库函数来实现应用程序的附加功能。
由于 Tkinter 是一个跨平台的 GUI 库,因此在 Windows 上编写的应用程序也可以在 macOS 和 Linux 设备上运行。但是,某些功能不支持跨平台功能,为此您必须参考文档中指定的附加工厂方法或函数。
示例
例如,如果我们想在 macOS 上以全屏显示 tkinter 应用程序,那么我们必须首先使用 **attributes('-fullscreen', True)** 方法为应用程序启用 **fullscreen** 属性。它使应用程序窗口保持全屏状态。
另一种有助于在 macOS 上禁用顶部工具栏的方法是 **overrideredirect(boolean)** 方法。它接受布尔值以启用和禁用导航栏上的工具栏。以下示例演示了它的工作原理。
# Import the library
from tkinter import *
from tkinter import filedialog
# Create an instance of window
win= Tk()
# Set the geometry of the window
win.geometry("700x350")
# Create a full screen window
win.attributes('-fullscreen', True)
win.overrideredirect(True)
# Create a label
Label(win, text= "Click the button to exit out of the fullscreen", font= ('Aerial 16 bold')).pack(pady= 15)
# Define a function to open a file in the system
def exit_program():
win.destroy()
# Create a button to trigger the dialog
button = Button(win, text="Exit", command=exit_program)
button.pack(pady= 20)
win.mainloop()输出
运行以上代码将显示一个全屏窗口,其中包含一个按钮和一个标签部件。该按钮可用于退出应用程序的全屏模式。

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP