【问题标题】:Tkinter class issueTkinter 类问题
【发布时间】:2017-11-12 13:08:19
【问题描述】:

我的目标是创建一个具有可以被其他窗口继承的窗口属性的默认类。

from tkinter import *
class window():
        def __init__(self, Width, Height, Bg):
            self.Width = Width
            self.Height = Height
            self.Bg = Bg

            object = Tk()
            frame = Frame(width=Width, height=Height, bg=Bg)
            frame.pack()


class child_login(window(768, 576, "ORANGE")):

    def __init__():


        Label(frame, text = "Username").grid(row=0)
        Label(frame, text = "Password").grid(row=1)
        e1=Entry(frame)
        e1.insert(10, "name")
        e1.grid(row=0, column=1)
        e2=Entry(frame, show = "*")
        e2.grid(row=1, column=1)
        Button(frame, text = "Quit", command = master.quit).grid(row=3, column=0)
        Button(frame, text = "print", command = display_entry).grid(row=3, column=1)
        mainloop()


child_login()

对于 child_login 类,我想要一个框架,它继承了 window() 属性,但在下面定义了标签和按钮。不幸的是,我创建了两个窗口并出现错误

tkinter.TclError: 屏幕距离错误“child_login”

【问题讨论】:

    标签: python-3.x class tkinter parameters


    【解决方案1】:

    继承类时不能初始化类。您首先继承类,然后然后分别启动它们。

    所以不要这样:

    class child_login(window(768, 576, "ORANGE")):
    

    这样做:

    class child_login(window):
    
        def __init__(self):
            window.__init__(self, 768, 576, "ORANGE")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-18
      • 2018-02-19
      • 1970-01-01
      • 2017-04-16
      • 1970-01-01
      • 2022-01-14
      • 2016-05-25
      • 2013-12-23
      相关资源
      最近更新 更多