Linked Questions

Popular Questions

Why does repr return dot?

Asked by At

I have a class that inherits after tkinter.Tk. I've overloaded the repr method, but when I try to print object of that class, I get dot instead.

import tkinter as tk


class Window(tk.Tk):
    def __init__(self, winsize=(1100, 900)):
        tk.Tk.__init__(self)
        self.winsize = winsize
        self.title('Bulbs')
        self.geometry(str(self.winsize[0]) + 'x' + str(self.winsize[1]))
        self.configure(background='white')

    def run(self):
        self.mainloop()

    def __repr__(self):
        return "Window: size={}".format(self.winsize)


w = Window()
print(w)

The output is: .

I want: Window: size=(1100, 900)

How can I achieve that?

Related Questions