<small id='rI14K'></small><noframes id='rI14K'>

      <i id='rI14K'><tr id='rI14K'><dt id='rI14K'><q id='rI14K'><span id='rI14K'><b id='rI14K'><form id='rI14K'><ins id='rI14K'></ins><ul id='rI14K'></ul><sub id='rI14K'></sub></form><legend id='rI14K'></legend><bdo id='rI14K'><pre id='rI14K'><center id='rI14K'></center></pre></bdo></b><th id='rI14K'></th></span></q></dt></tr></i><div id='rI14K'><tfoot id='rI14K'></tfoot><dl id='rI14K'><fieldset id='rI14K'></fieldset></dl></div>
      1. <legend id='rI14K'><style id='rI14K'><dir id='rI14K'><q id='rI14K'></q></dir></style></legend>
        • <bdo id='rI14K'></bdo><ul id='rI14K'></ul>

      2. <tfoot id='rI14K'></tfoot>

        为什么设置窗口图标时没有定义 .ico 文件?

        Why isn#39;t .ico file defined when setting window#39;s icon?(为什么设置窗口图标时没有定义 .ico 文件?)
          <i id='HKGtT'><tr id='HKGtT'><dt id='HKGtT'><q id='HKGtT'><span id='HKGtT'><b id='HKGtT'><form id='HKGtT'><ins id='HKGtT'></ins><ul id='HKGtT'></ul><sub id='HKGtT'></sub></form><legend id='HKGtT'></legend><bdo id='HKGtT'><pre id='HKGtT'><center id='HKGtT'></center></pre></bdo></b><th id='HKGtT'></th></span></q></dt></tr></i><div id='HKGtT'><tfoot id='HKGtT'></tfoot><dl id='HKGtT'><fieldset id='HKGtT'></fieldset></dl></div>

          <small id='HKGtT'></small><noframes id='HKGtT'>

          <tfoot id='HKGtT'></tfoot>
            <tbody id='HKGtT'></tbody>
          <legend id='HKGtT'><style id='HKGtT'><dir id='HKGtT'><q id='HKGtT'></q></dir></style></legend>
            <bdo id='HKGtT'></bdo><ul id='HKGtT'></ul>

                1. 本文介绍了为什么设置窗口图标时没有定义 .ico 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我尝试使用下面的代码将左上角的窗口图标从难看的红色TK"更改为我自己的 favicon 时,Python 抛出了一个错误:

                  When I tried to change the window icon in the top left corner from the ugly red "TK" to my own favicon using the code below, Python threw an error:

                  from tkinter import *
                  root = Tk()
                  
                  #some buttons, widgets, a lot of stuff
                  
                  root.iconbitmap('favicon.ico')
                  

                  这应该将图标设置为favicon.ico"(根据网络上的许多论坛帖子).但不幸的是,这一行所做的只是抛出以下错误:

                  This should set the icon to 'favicon.ico' (according to a lot of forum posts all over the web). But unfortunately, all this line does is throw the following error:

                  Traceback (most recent call last):
                    File "d:ladvclientmainapp.py", line 85, in <module>
                      root.iconbitmap(bitmap='favicon.ico')
                    File "C:Python33lib	kinter\__init__.py", line 1637, in wm_iconbitmap
                      return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
                  _tkinter.TclError: bitmap "favicon.ico" not defined
                  

                  我已经做了什么:

                  • 我检查了路径 - 一切都 100% 正确
                  • 我尝试了其他文件格式,例如 .png.bmp - 都没有成功
                  • 我在很多网站上都查过这个问题
                  • I checked the path - everything is 100% correct
                  • I tried other file formats like .png or .bmp - none worked
                  • I looked this problem up on many websites

                  第三点,我最喜欢的关于 Tkinter 的网站 effbot.org 告诉我,Windows 忽略了 iconbitmap 功能.但这并不能解释为什么会抛出错误!

                  And for the third point, effbot.org, my favorite site about Tkinter, told me that Windows ignores the iconbitmap function. But this doesn't explain why it throws an error!

                  有一些hackish"方法可以避免这个问题,但它们都不是为 Python 3.x 编写的.

                  There are some "hackish" ways to avoid that issue, but none of them are Written for Python 3.x.

                  所以我的最后一个问题是:有没有办法使用 Python 3.x 和 Tkinter 获得自定义图标?

                  So my final question is: Is there a way to get a custom icon using Python 3.x and Tkinter?

                  另外,不要告诉我应该使用另一个 GUI 库.我希望我的程序可以在每个平台上运行.我还想要一个编码版本,而不是 py2exesth 解决方案.

                  Also, don't tell me I should use another GUI Library. I want my program to work on every platform. I also want a coded version, not a py2exe or sth solution.

                  推荐答案

                  您需要将 favicon.ico 与您的脚本放在同一个文件夹或字典中,因为 python 只在当前字典中搜索或者您可以输入完整的路径名.例如,这有效:

                  You need to have favicon.ico in the same folder or dictionary as your script because python only searches in the current dictionary or you could put in the full pathname. For example, this works:

                  from tkinter import *
                  root = Tk()
                  
                  root.iconbitmap(r'c:Python32DLLspy.ico')
                  root.mainloop()
                  

                  但这会导致您出现同样的错误:

                  But this blows up with your same error:

                  from tkinter import *
                  root = Tk()
                  
                  root.iconbitmap('py.ico')
                  root.mainloop()
                  

                  这篇关于为什么设置窗口图标时没有定义 .ico 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                2. <legend id='8KlHy'><style id='8KlHy'><dir id='8KlHy'><q id='8KlHy'></q></dir></style></legend>

                      <tbody id='8KlHy'></tbody>

                    <small id='8KlHy'></small><noframes id='8KlHy'>

                        <bdo id='8KlHy'></bdo><ul id='8KlHy'></ul>
                          <tfoot id='8KlHy'></tfoot>
                          <i id='8KlHy'><tr id='8KlHy'><dt id='8KlHy'><q id='8KlHy'><span id='8KlHy'><b id='8KlHy'><form id='8KlHy'><ins id='8KlHy'></ins><ul id='8KlHy'></ul><sub id='8KlHy'></sub></form><legend id='8KlHy'></legend><bdo id='8KlHy'><pre id='8KlHy'><center id='8KlHy'></center></pre></bdo></b><th id='8KlHy'></th></span></q></dt></tr></i><div id='8KlHy'><tfoot id='8KlHy'></tfoot><dl id='8KlHy'><fieldset id='8KlHy'></fieldset></dl></div>