So basically i am going to write a program of python tkinter to show weight, however the variables and the objects are distracting me.
My code is like this:
from tkinter import *
import tkinter as tk
#object oriented BMI project
class Root(Tk):
def __init__(self):
super(Root, self).__init__()
#Info Bar
self.title("Shushu BMI Calculator")
self.geometry("1100x600")
#self.resizable("False")
#var
self.weight = tk.StringVar()
#self.w = tk.StringVar()
#Caption
self.caption = tk.Label(text = "BMI Calculator - Beta 2.0",
fg = "brown",
font="Arial 40")
self.caption.grid(column = 0, row = 0, sticky = "N")
#Copyright
self.copyright = tk.Label(text = "Powered by Shushu Studio",
fg = "green",
font = "Arial 20")
self.copyright.grid(column = 1, row = 0, sticky = "E")
#Weight input Row
self.weightInputTag = tk.Label(text="Please input your weight here (kg)")
self.weightInputTag.grid(column = 0, row = 1, sticky = "W")
self.weightEntry = tk.Entry(textvariable = self.weight)
self.weightEntry.grid(column = 0, row = 1)
self.weightSubmit = tk.Button(text="Submit",
COMMAND=self.weightget)
self.weightSubmit.grid(column = 0, row = 2)
self.showWeight = tk.Label(text="")
self.showWeight.grid(column = 0, row = 3)
def weightget(self):
weight = self.weightEntry.get()
self.showWeight.configure(text=weight)
root = Root()
root.mainloop()
And the console show this:
Resetting Python state.
Running P:\2020\09\25\bmi.py
The interactive Python process has exited.
Traceback (most recent call last):
File "P:\2020\09\25\bmi.py", line 52, in <module>
root = Root()
File "P:\2020\09\25\bmi.py", line 41, in __init__
COMMAND=self.weightget)
File "P:\Language\lib\tkinter\__init__.py", line 2345, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'weightget'
Please help, thanks very much!