简体   繁体   English

Python Tkinter标签刷新失败

[英]Python Tkinter Label Refresh Woes

Im back again with another python issue. 我再次遇到另一个python问题。 A short while ago I wrote a console based program that pulls stats from a bitcoin miner on your local network. 不久前,我编写了一个基于控制台的程序,该程序从您本地网络上的比特币矿工获取统计信息。 I've decided I'd like to turn it into a gui, and choose a combination of EasyGUI and Tkinter for my program. 我决定将其转换为gui,并为我的程序选择EasyGUI和Tkinter的组合。

My input boxes (ip, refresh rate,asic type) are all using EasyGUI, simply to save lines of code as Tkinter would take far more writing to accomplish the same. 我的输入框(ip,刷新率,asic类型)都使用EasyGUI,只是为了节省代码行,因为Tkinter要花费更多的时间来完成同样的工作。 However, My actual results page is written using Tkinter as it allows me to refresh the displayed data at a user-defined interval. 但是,我的实际结果页面是使用Tkinter编写的,因为它允许我以用户定义的时间间隔刷新显示的数据。

My issue is this: I had my program running happily, and then made some small ui tweaks (title, font, etc) and now after my most recent compile (using pyinstaller) I've noticed the stats (labels) don't update at all. 我的问题是这样的:我让程序快乐地运行,然后进行了一些小的ui调整(标题,字体等),现在在最近一次编译(使用pyinstaller)之后,我注意到统计信息(标签)没有更新完全没有 I have looked over my code countless times now and cannot seem to find what is blocking the stats from changing at the defined intervals. 我已经无数次地查看了我的代码,似乎无法找到阻止统计信息按定义的时间间隔更改的内容。

I am hoping someone with a fresh pair of eyes can help me find my stupid mistake, as it was running perfectly before these small additions. 我希望有一双新鲜的眼睛的人可以帮助我找到我的愚蠢错误,因为在添加这些小东西之前它运行得很好。

Heres a cut-down version that still runs and produces the same issue: 这是仍然运行并产生相同问题的简化版本:

import Tkinter as tk

from pycgminer import CgminerAPI

cgminer = CgminerAPI()
cgminer.host = 192.168.x.x
summary = cgminer.summary()
update = 1000
def L1(label):
    def hashrate():
        msg = "Your current GH/S = "
        speed = msg , summary['SUMMARY'][0]['GHS 5s']
        label.config(text=speed)
        label.after(update, hashrate)
    hashrate()
root = tk.Tk()
root.title("Eyes On Miner GUI V0.2")
label = tk.Label(root)
label.pack()
L1(label)
root.mainloop()

Full code on pastebin, in case you'd like to try to run it yourself. 完整的代码在pastebin上,以防您想自己运行它。 (python 2.7) Full Code (python 2.7) 完整代码

I ran this much of your code, substituting time() for the summary. 我运行了很多代码,用time()代替了摘要。 It works in IDLE. 它在IDLE中工作。 From the console, either run with python -i program.py or add root.mainloop . 在控制台上,使用python -i program.py运行或添加root.mainloop

import tkinter as tk
from time import time

update = 1000
def L1(label):
    def hashrate():
        msg = "Your current GH/S = "
        speed = msg , time()
        label.config(text=speed)
        label.after(update, hashrate)
    hashrate()
root = tk.Tk()
root.title("Eyes On Miner GUI V0.2")
label = tk.Label(root)
label.pack()
L1(label)

If the problem is not with summary['SUMMARY'][0]['GHS 5s'] , then there must be an incompatibility with either CgminerAPI or more likely with easygui . 如果问题不在于summary['SUMMARY'][0]['GHS 5s'] ,则必须与CgminerAPI或更不兼容easygui The latter is meant to replace tkinter, not be used together with it. 后者旨在代替tkinter,而不是与其一起使用。 If the code worked at first and then quit, then one of the additional functions you used must have triggered a conflict. 如果代码先工作然后退出,则您使用的其他功能之一必须引发了冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM