简体   繁体   中英

Python Tkinter Label Refresh Woes

Im back again with another python issue. 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.

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. However, My actual results page is written using Tkinter as it allows me to refresh the displayed data at a user-defined interval.

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. 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. (python 2.7) Full Code

I ran this much of your code, substituting time() for the summary. It works in IDLE. From the console, either run with python -i program.py or add 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 . The latter is meant to replace tkinter, not be used together with it. If the code worked at first and then quit, then one of the additional functions you used must have triggered a conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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