But do not tell me how to call another from one GUI window? (Program code in Python.)

Added from comment.

Well, here is the simplest example, I create a file proba.py:

from Tkinter import* tk1=Tk() 

Next, create a file with which I want to open the previous one:

 # -*- coding: cp1251 -*- from Tkinter import* from proba import* def button1_clicked(): tk1.mainloop() button1=Button(text=u'жми!',command=button1_clicked) button1.pack() tk=Tk() tk.mainloop() 

As a result, both windows come out, while the button essentially does not work ...

  • one
    And what does it mean to call another from one GUI window? - alexlz
  • 2
    What interface and operating system are we talking about? PyGTK, PyQT4? - stanislav
  • System windows 7. I make a graphical interface, I know how to connect modules to the program, I want to open a different interface when I press a button ... It’s just an error when accessing the module and the program doesn’t work properly. - Vasya
  • one
    It looks like confusion with terminology. Try not to use unnecessarily complicated foreign words, but try to explain on your fingers. And preferably with a demonstration of non-working code. - alexlz
  • Moved to the question. - Vasya

2 answers 2

C tkinter this trick will not work. Two instances of Tk () in the same script will not work correctly.

Two options:

  1. Rewrite the windowed interface in the imported script from a standalone frame to the Toplevel widget. The multi-window interface in tkinter is implemented this way. Examples will find.
  2. If you are too lazy to rewrite, call the module as a separate process:

    import subprocess

    button1 = Button (text = u'zhmi! ', command = lambda: subprocess.Popen (' proba.py '))

  • The first is normal. This is how everything in tk (which is used in tkinter) and other event-driven applications is done. The second, even if it will work - some kind of cunning perversion. mainloop - "main loop", waiting for events. They are two in one stream can not be. - alexlz

The second window draws your import , not the function.