ubuntu 中的 Python 3 tkinter iconbitmap 错误 [英] Python 3 tkinter iconbitmap error in ubuntu

查看:119
本文介绍了ubuntu 中的 Python 3 tkinter iconbitmap 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有这个:

import tkinter
gui = tkinter.Tk()
gui.iconbitmap(default='/home/me/PycharmProjects/program/icon.ico')
gui.mainloop()`

但是当我运行时出现错误提示

But when I run I get an error saying

Traceback (most recent call last):
File "/home/spencer/PycharmProjects/xMinecraft/GUI.py", line 17, in <module>
gui.iconbitmap(default='/home/me/PycharmProjects/program/icon.ico')
File "/usr/lib/python3.3/tkinter/__init__.py", line 1638, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
_tkinter.TclError: wrong # args: should be "wm iconbitmap window ?bitmap?"`

我正在尝试使用 tkinter 来设置我制作的图标的窗口.我正在使用安装在 ubuntu 13.10 上的 Pycharm.我尝试了各种方法,从将 '/' 更改为 '\' 并在前面添加 Z://,因为这是我的分区名称.但我仍然收到错误,所以请帮忙.

I'm trying to use tkinter to set a window I've made's icon. I'm using Pycharm installed on ubuntu 13.10. I've tried various things from changing '/' to '\' and adding a Z:// to the front because that's my partition's name. But I still get the error so please help.

推荐答案

您需要将路径指定为第一个位置参数,或者使用关键字参数位图".它的文档很差,但需要位图参数;你不能只给出 default 关键字参数.事实上,bitmap 关键字参数在 python 3 中已经被删除了.

You need to either specify the path as the first positional argument, or use the keyword argument "bitmap". It's rather poorly documented, but the bitmap argument is required; you can't just give the default keyword argument. In fact, the bitmap keyword argument has been removed in python 3.

但是,您只能在 Windows 上使用 .ico 文件.在 ubuntu 和其他 linux 机器上,您需要使用 .xbm 文件,并需要以@"作为前缀

However, you can only use .ico files on windows. On ubuntu and other linux boxes you need to use a .xbm file, and need to prefix it with "@"

这仅适用于 Windows:

This should work on windows only:

gui.iconbitmap('/home/me/PycharmProjects/program/icon.ico')

在 ubuntu 上,它需要是这样的:

On ubuntu, it would need to be something like this:

gui.iconbitmap('@/home/me/PyCharmProjets/program/icon.xbm')

您不能只是将 .ico 文件重命名为 .xbm,它们是完全不同的文件格式.

You can't just rename a .ico file to .xbm, they are completely different file formats.

这篇关于ubuntu 中的 Python 3 tkinter iconbitmap 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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