There is a module_0 where it is stored until an undefined variable, for example tk :

 tk: 'tk.Tk()' = None 

There is a module_1 where tk defined:

 import module_0 module_0.tk = tk.Tk() 

There is a module_2 where tk used:

 import module_0 module_0.tk.after() # тут не понимает что tk это tk.Tk() 

PyCharm does not understand that tk.Tk() lies in tk, for example, it does not continue .after , but it continues .StringVar , etc. It doesn’t understand the anotation with custom classes. All the latest versions.

How to change so that refactoring works?

  • one
    It seems you misunderstand the meaning of the word "refactoring" - Xander
  • one
    Well, you import tk from module_0. Why do you expect PyCharm to take into account the value from module_1? - Xander
  • I expect that it uses an anotation from module_0, which for user classes does not work at all - vadim vaduxa pm

1 answer 1

I do not have a Tkinter computer on my computer, and I cannot reproduce exactly your code.

But as far as I can simulate the situation in other classes, your problem is as follows:

Annotation of variables requires the type as the type. And not an instance of this type.

You, as an annotation, pass exactly an instance of the type tk.Tk (which is indicated by the parentheses). Try removing the parentheses from the annotation - and everything should work:

 tk: 'tk.Tk' = None