0

I am trying to update my meter widget with the results of a ping test using pyspeedtest, but I keep getting the error: "TypeError: Meter.configure() missing 1 required positional argument: 'self'" The ping function works without any issues, I just can't seem to figure out how to pass the ping result to the meters "amountused" parameter to change the widget.

from tkinter import *
from tkinter.ttk import *
import ttkbootstrap as ttk
import pyspeedtest

root = Tk()
window = style.master
window_width = 300
window_height = 300
root.resizable(False, False)

ping_meter = ttk.Meter

ping_meter(
    master=root,
    metersize=300,
    padding=20,
    amountused=0,
    metertype='semi',
    subtext='milliseconds',
    interactive=False
).grid(sticky=N, row=0, column=1, padx=10, pady=10)

myping = IntVar()

def ping_test():
   t = pyspeedtest.SpeedTest(e1.get())
   myping.set(t.ping())
   ping_meter.configure(amountused = myping)

Label(root, text="Website URL:").grid(sticky=W, row=2, padx=10, pady=10)
Label(root, text="Ping Result:").grid(sticky=W, row=3, padx=10, pady=10)

result = Label(root, text="", textvariable=myping).grid(sticky=W, row=3, column=1, padx=10, pady=10)

e1 = Entry(root)
e1.grid(row=2, column=1)
b = Button(root, text="Check", command=ping_test)
b.grid(sticky=W, row=2, column=3, padx=10, pady=10)

mainloop()
TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • Maybe use `ping_meter = ttk.Meter(master=root, ...`, instead of having `ping_meter = ttk.Meter` and `ping_meter(master=root` on separate lines. How it is right now, you initialize `ping_meter`, but don't assign the initialized class to a variable. – Sylvester Kruin Dec 30 '21 at 15:59
  • Hi @SylvesterKruin, I made some adjustments based on your suggestion.. Now the meter is updating it's amountused text, however the result is "PY_VAR3" instead of the numerical ping value result. Any thoughts? – Steven Klinck Dec 30 '21 at 16:18
  • 1
    @StevenKlinck Use `get()` to get its content: `ping_meter.configure(amountused=myping.get())` – Delrius Euphoria Dec 30 '21 at 16:37

1 Answers1

0

the line ping_meter = ttk.Meter creates the variable ping_meter which is just the class ttk.Meter. therefore .configure() doesn't work. when you create an instance it isn't assigned to any variable, instead try doing this to create an instance of ttk.Meter, note that .grid() is called separately.

ping_meter = ttk.Meter(
    master=root,
    metersize=300,
    padding=20,
    amountused=0,
    metertype='semi',
    subtext='milliseconds',
    interactive=False
)
ping_meter.grid(sticky=N, row=0, column=1, padx=10, pady=10)

also in ping_test() use ping_meter.configure(amountused = t) instead.

Hadrian
  • 917
  • 5
  • 10
  • Hi @Hadrian, Thanks for commenting. I did as you and SylvesterKruin suggested.. Now the meter is updating it's amountused text, however the result is "PY_VAR3" instead of the numerical ping value result. Any thoughts? – Steven Klinck Dec 30 '21 at 16:24
  • I edited my answer – Hadrian Dec 30 '21 at 21:52