繁体   English   中英

Python - Tkinter空窗口

[英]Python - Tkinter empty window

我正在为一门课程做一个作业,我不确定代码是什么,但它运行没有错误,只显示一个空窗口。 我使用了一个示例作为开始,并基本上修改它以获取此代码。 如果需要,我可以提供示例代码进行比较。

    from Tkinter import *

class App(Tk):
  def __init(self):
        Tk.__init__(self)

        self.height()
        self.weigh()
        self.calculate()
        self.output()


  def height(self):

        Label(self, text = "Enter Height, feet").grid()

        self.feet = Entry(self)
        self.feet.grid(row = 0, column = 1)
        self.feet.insert(0, "100")

        lblinches = Label(self, text = "Enter Height, inches")
        lblinches.grid(row = 1, column = 0)

        self.inches = Entry(self)
        self.inches.grid(row = 1, column = 1)

  def weigh(self):

        Label(self, text = "Enter Weight").grid(row =2, column = 0)

        self.weight = Entry(self)
        self.weight.grid(row = 2, column = 1)


  def output(self):
        self.calcBMI = Button(self, text = "Calculate BMI")
        self.calcBMI.grid()
        self.calcBMI["command"] = self.calculate

        Label(self, text = "Body Mass Index").grid(row = 4)

        Label(self, text = "Status").grid(row = 5)    

  def calculate(self):

        feet1 = int(self.feet.get())
        inches1 = int(self.inches.get())
        height1 = feet1 *12 + inches1
        weight1 = int(self.weight.get())

        bmi = (weight1 * 703) / (height1 * 2)
        self.lblbmi["text"] = ".2f" % bmi


def main():

    app = App()
    app.mainloop()

main()

__init应该是__init__ 由于未定义__init__因此未调用任何配置方法。

暂无
暂无

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

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