我可以为 tkinter 图标使用哪些文件格式? [英] Which file formats can I use for tkinter icons?

查看:69
本文介绍了我可以为 tkinter 图标使用哪些文件格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know this might be obvious, but in tkinter you can set an icon, but I have found it really hard to find one. I just wanted to know if you have to use the .ico format for the file or if there is a way to use .png or .jpeg files.

目前我有

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

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

That is the whole setup I have and I just want to know about line 4:

window.wm_iconbitmap("Icon.ico") 

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

Thanks for responding to my question, although i am sorry for not spending more time looking into the question rather than just asking here.

推荐答案

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

effbot.org 上的文档说明了以下内容iconbitmap(bitmap=None)

Let's start by reading the documentation!

The documentation at effbot.org says the following regarding iconbitmap(bitmap=None)

设置或获取此窗口图标化时要使用的图标位图.某些窗口管理器(包括 Windows)会忽略此方法.

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

请注意,此方法只能用于显示单色图标.要显示彩色图标,请将其放在Label 小部件中,然后使用iconwindow 方法显示.

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.

wm_iconbitmap 相同.

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

设置或获取图标窗口以在此窗口被图标化时用作图标.某些窗口管理器(包括 Windows)会忽略此方法.

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

wm_iconwindow 相同.

窗口

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

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

According to this other documentation, which actually says the same things as the docstrings of the homonymous method for tkinter in (at least) Python 2.7, 3.5 and 3.6:

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

将图标化小部件的位图设置为bitmap.如果没有给出,则返回位图.

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

在 Windows 下,default 参数可用于为小部件和任何没有明确设置图标的后代设置图标.default 可以是 .ico 文件的相对路径(例如:root.iconbitmap(default='myicon.ico')).有关详细信息,请参阅 Tk 文档.

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 文档:

So here's the original Tk documentation:

wm iconbitmap 窗口?位图?

如果指定了位图,则它以 Tk 接受的标准形式命名位图(参见 Tk_GetBitmap 手动输入以了解详细信息).这个位图被传递给窗口管理器以显示在窗口的图标中,并且该命令返回一个空字符串.如果为bitmap 指定了空字符串,则取消window 的任何当前图标位图.如果指定了bitmap,则该命令返回一个空字符串.否则,它返回与 window 关联的当前图标位图的名称,如果 window 没有图标位图,则返回一个空字符串.

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 是您的顶级窗口(TkToplevel 的实例>).

From my understanding of Tcl, here window is your toplevel window (either an instance of Tk or Toplevel).

在 Windows 操作系统上,支持附加标志:

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

wm iconbitmap window ?-default? ?image?

如果给定了 -default 标志,则图标将应用于尚未应用其他特定图标的所有顶级窗口(现有和未来).

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.

除了位图图像类型,还接受包含有效 Windows 图标的任何文件的完整路径规范(通常是 .ico.icr 文件),或外壳为其分配了图标的任何文件.

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 将首先测试文件是否包含图标,然后它是否具有指定的图标,最后,如果失败,则测试位图.

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.

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

Not very concrete and thus helpful answer so far.

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

The iconbitmap function (or method, depending on the programming language) should be used to set a bitmap image to the window when the window is iconified.

在 Windows 上,您可以为包含 有效的 Windows 图标 也被接受(通常是 .ico.icr> 文件),或外壳为其分配了图标的任何文件.

On Windows you're allowed to set 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.

  1. xbmxpm(用于X Window System)

根据我将位图"链接到上面的维基百科文章:

According to the Wikipedia article to which I linked "bitmap" to above:

X 窗口系统黑白图像使用类似的xbm格式,而xpm用于彩色图像....

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

  • BMP 文件格式

    Netpbm 格式

    .wbmp

    ILBM

    ...

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

    So most of the bitmap file formats are not cross-platform! In other words, if someone tells you to use a xbm image for the icon, it may not work on your platform because xbm are bitmaps for X Window System.

    注意:即使在回答这个问题之后,您仍然可能遇到问题!

    Note: even after this answer you may still have problems!

    这篇关于我可以为 tkinter 图标使用哪些文件格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆