当我尝试使用下面的代码将丑陋的红色"TK"左上角的窗口图标更改为我自己的图标时,Python发出错误:
from tkinter import *
root = Tk()
#some buttons, widgets, a lot of stuff
root.iconbitmap('favicon.ico')
Run Code Online (Sandbox Code Playgroud)
这应该将图标设置为'favicon.ico'(根据网络上的很多论坛帖子).但不幸的是,所有这一行都抛出以下错误:
Traceback (most recent call last):
File "d:\ladvclient\mainapp.py", line 85, in <module>
root.iconbitmap(bitmap='favicon.ico')
File "C:\Python33\lib\tkinter\__init__.py", line 1637, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "favicon.ico" not defined
Run Code Online (Sandbox Code Playgroud)
我已经做了什么:
.png或.bmp没有工作而对于第三点,我最喜欢的关于Tkinter的网站effbot.org告诉我,Windows忽略了这个iconbitmap功能.但这并不能解释为什么会抛出错误!
有一些"hackish"方法可以避免这个问题,但没有一个是为Python 3.x编写的.
所以我的最后一个问题是:有没有办法使用Python 3.x和Tkinter获取自定义图标?
另外,不要告诉我应该使用另一个GUI库.我希望我的程序能够在每个平台上运行.我也想要一个编码版本,而不是一个py2exe或sth解决方案.
GlobalScope我正在重构一些目前在基于结构化并发的方法上启动协程的 Kotlin 代码。我需要在 JVM 退出之前加入代码中启动的所有作业。我的类可以分解为以下接口:
interface AsyncTasker {
fun spawnJob(arg: Long)
suspend fun joinAll()
}
Run Code Online (Sandbox Code Playgroud)
用法:
fun main(args: Array<String>) {
val asyncTasker = createAsyncTasker()
asyncTasker.spawnJob(100)
asyncTasker.spawnJob(200)
asyncTasker.spawnJob(300)
asyncTasker.spawnJob(500)
// join all jobs as they'd be killed when the JVM exits
runBlocking {
asyncTasker.joinAll()
}
}
Run Code Online (Sandbox Code Playgroud)
基于我的GlobalScope实现如下所示:
class GlobalScopeAsyncTasker : AsyncTasker {
private val pendingJobs = mutableSetOf<Job>()
override fun spawnJob(arg: Long) {
var job: Job? = null
job = GlobalScope.launch(Dispatchers.IO) {
someSuspendFun(arg)
pendingJobs.remove(job)
}
pendingJobs.add(job)
}
override suspend …Run Code Online (Sandbox Code Playgroud) 我想创建一个在更改时OptionMenu编辑另一个的tkinter OptionMenu.所以我尝试创建一个command=参数,使得每次更新时都会运行一个特定的命令OptionMenu,就像我将command=参数用于按钮,旋转框等时一样.
tl.wktype = OptionMenu(tl,wktypevar, *wk_types,command=typeupdate)
Run Code Online (Sandbox Code Playgroud)
代码中的其他位置是typeupdate()Command - 用于调试目的.
def typeupdate():
typeval = tl.wktype.get()
print(typeval)
Run Code Online (Sandbox Code Playgroud)
python抛出的异常如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Python33\lib\tkinter\__init__.py", line 3300, in __call__
self.__callback(self.__value, *args)
TypeError: typeupdate() takes 0 positional arguments but 1 was given
Run Code Online (Sandbox Code Playgroud)
确实typeupdate()给出了什么位置参数以及如何解决这个问题?
程序员大家好,
今天我想用Python 3.3从这个网站上获取一些JSON数据:http://ladv.de/api/-apikey-redacted-/ausDetail?id = 884&wettbewerbe = true&all = true
官方API告诉我,调用此URL会返回一些JSON数据.但是,如果我使用以下代码来获取它(我也在stackoverflow上找到它),它会抛出一个错误:
import urllib.request
import json
request = 'http://ladv.de/api/mmetzger/ausDetail?id=884&wettbewerbe=true&all=true'
response = urllib.request.urlopen(request)
obj = json.load(response)
str_response = response.readall().decode('utf-8')
obj = json.loads(str_response)
print(obj)
Run Code Online (Sandbox Code Playgroud)
打印出来
Traceback (most recent call last):
File "D:/ladvclient/testscrape.py", line 5, in <module>
response = urllib.request.urlopen(request)
File "C:\Python33\lib\urllib\request.py", line 156, in urlopen
return opener.open(url, data, timeout)
File "C:\Python33\lib\urllib\request.py", line 475, in open
response = meth(req, response)
File "C:\Python33\lib\urllib\request.py", line 587, in http_response
'http', request, response, code, msg, hdrs) …Run Code Online (Sandbox Code Playgroud)