Script does not work outside of IDLE

0

The following code can be executed from IDLE (a Python IDE) in 32-bit Python 3.6 on Windows 7 (64 bits)

import tkinter  
def algo():
    pass
def ventanan1():
   Ventana1=tkinter.Toplevel()
   Ventana1.geometry("250x100")
   Ventana1.title("Ventana 1")
   BotonQueEjecuta1 = tkinter.Button(Ventana1, text="Ejecutar", command=ventanan2)
   BotonQueEjecuta1.place(x=0,y=0)
def ventanan2():
    Ventana2=tkinter.Toplevel()
    Ventana2.geometry("250x100")
    Ventana2.title("Ventana 2")
    BotonQueEjecuta2 = tkinter.Button(Ventana2, text="Ejecutar", command=ventanan3)
    BotonQueEjecuta2.place(x=0,y=0) 
def ventanan3():
    Ventana3=tkinter.Toplevel()
    Ventana3.geometry("250x100")
    Ventana3.title("Ventana 3")
    BotonQueEjecuta3 = tkinter.Button(Ventana3, text="Ejecutar", command=algo)
    BotonQueEjecuta3.place(x=0,y=0)
root = tkinter.Tk()
root.title("Ventana 0") 
root.geometry("800x800")
BotonQueEjecuta = tkinter.Button(root, text="Ejecutar", command=ventanan1)
BotonQueEjecuta.place(x=0,y=0)
root.mainloop

The problem is when using it from the interpreter in the style of "python miscript.py" it just does not do anything, it does not throw any errors or anything, it does not show anything

How can I do it from outside IDLE? only there it works

    
asked by Bryan Figueroa 15.03.2017 в 03:33
source

2 answers

0

The error is actually quite simple, you are not calling the mainloop , you are missing the parentheses. This causes the application tkinter not to start the main window as it can not be otherwise. Simply the last line is:

root.mainloop

When it should be:

root.mainloop()

The question that we all ask ourselves is: why does the IDLE not give a damn whether the main buzzer is called or not? As it turns out that the same IDLE is an application tkinter and has its own mainloop internal% as is logical, this makes the events of your program are processed thanks to the loop IDLE itself.

When you cast it using the interpreter there is no infinite cycle waiting for the events of your program since you do not get to call the mainloop() method for not using the parentheses.

    
answered by 18.03.2017 / 02:53
source
0

Let's try several reasons:

  • Python binding is not working on your console: Have you already tried python, with some other script, from the console?

  • The version of python you're running is different from the one you run in IDLE: Can you try calling your python as python3 miscript.py and see if that works?

  • It is not necessary to debug your code or your environment is not ready. use pip install tkinter before running the code (Although I doubt this is the problem)

  • One way to know if things are working is to integrate some prints. That helps separate the logic of SO problems. Can you try adding some prints to know how it is working?

  • The tkinter library requires tk which is an external dependency. Is it well installed? In the tk guide, recommend ActiveTcl . Source: link

answered by 16.03.2017 в 15:37