gpt4 book ai didi

python - 我可以为 tkinter 图标使用哪些文件格式?

转载 作者:行者123 更新时间:2023-11-28 22:30:01 24 4
gpt4 key购买 nike

我知道这可能很明显,但在 tkinter 中你可以设置一个图标,但我发现很难找到一个。我只是想知道您是否必须为文件使用 .ico 格式,或者是否有办法使用 .png.jpeg 文件。

目前我有

window = Tkinter.Tk()
window.title("Weclome!")
window.geometry("200x300")
window.wm_iconbitmap("Icon.ico")
window.configure(background = "Black")

这就是我的全部设置,我只想知道第 4 行:

window.wm_iconbitmap("Icon.ico") 

感谢您回答我的问题,但很抱歉没有花更多时间研究这个问题而只是在这里提问。

最佳答案

让我们从阅读文档开始吧!

文档位于 effbot.org关于 iconbitmap(bitmap=None)

的说明如下

Sets or gets the icon bitmap to use when this window is iconified. This method is ignored by some window managers (including Windows).

Note that this method can only be used to display monochrome icons. To display a color icon, put it in a Label widget and display it using the iconwindow method instead.

Same as wm_iconbitmap.

所以这是关于iconwindow(window=None)的文档:

Sets or gets the icon window to use as an icon when this window is iconified. This method is ignored by some window managers (including Windows).

Same as wm_iconwindow.

window

The new icon window. If omitted, the current window is returned.

根据这个other documentation ,这实际上与(至少)Python 2.7、3.5 和 3.6 中 tkinter 的同名方法的文档字符串说的相同:

wm_iconbitmap(self, bitmap=None, default=None)

Set bitmap for the iconified widget to bitmap. Return the bitmap if None is given.

Under Windows, the default parameter can be used to set the icon for the widget and any descendents that don't have an icon set explicitly. default can be the relative path to a .ico file (example: root.iconbitmap(default='myicon.ico') ). See Tk documentation for more information.

所以这是原始的 Tk 文档:

wm iconbitmap window ?bitmap?

If bitmap is specified, then it names a bitmap in the standard forms accepted by Tk (see the Tk_GetBitmap manual entry for details). This bitmap is passed to the window manager to be displayed in window's icon, and the command returns an empty string. If an empty string is specified for bitmap, then any current icon bitmap is canceled for window. If bitmap is specified then the command returns an empty string. Otherwise, it returns the name of the current icon bitmap associated with window, or an empty string if window has no icon bitmap.

根据我对 Tcl 的理解,这里的 window 是您的顶层窗口(Tk 的实例或 Toplevel).

On the Windows operating system, an additional flag is supported:

wm iconbitmap window ?-default? ?image?

If the -default flag is given, the icon is applied to all toplevel windows (existing and future) to which no other specific icon has yet been applied.

In addition to bitmap image types, a full path specification to any file which contains a valid Windows icon is also accepted (usually .ico or .icr files), or any file for which the shell has assigned an icon.

Tcl will first test if the file contains an icon, then if it has an assigned icon, and finally, if that fails, test for a bitmap.

到目前为止还不是很具体,因此很有帮助。


我的结论

iconbitmap 函数(或方法,取决于编程语言)应该用于设置 bitmap当窗口被图标化时图像到窗口。

在 Windows 上,您可以为包含 valid Windows icon 的任何文件设置完整路径规范。也接受(通常是 .ico.icr 文件),或 shell 已为其分配图标的任何文件。

那么哪些图片是位图呢?

  1. xbmxpm (对于 X 窗口系统)

    根据Wikipedia article我将“位图”链接到上面:

    The X Window System uses a similar xbm format for black-and-white images, and xpm for color images. ...

  2. BMP file format

  3. Netpbm format

  4. .wbmp

  5. ILBM

    ...

所以大多数位图文件格式不能跨平台!换句话说,如果有人告诉您使用 xbm 图像作为图标,它可能无法在您的平台上运行,因为 xbmX Window System< 的位图/em>.

注意:即使在这个答案之后你可能仍然有问题!


其他可能有用的文章

关于python - 我可以为 tkinter 图标使用哪些文件格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42705547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com