Error with window creation using Tkinter

Asked

Viewed 19 times

-2

that’s the code I’m trying to run:

from tkinter import *
janela = Tk()
janela.mainloop()
janela.geometry(450x450)
janela.title('calculadora GUI')

He would open the window normally before I added janela.geometry(450x450) but ignored janela.title('calculadora GUI') opening the window named Tk, now it doesn’t even open, "syntax error" and highlights '450x'.

Problem basiquinho, but I am very beginner really... I thank you for giving of now

1 answer

2


The error occurs for two causes.

  • Are you calling the mainloop at first, preventing the code from executing the rest, so it does not change the title nor the size
  • To function geometry() receives as parameter a string and you’re passing a number.

To correct this:

from tkinter import *
janela = Tk()
janela.title('calculadora GUI')
janela.geometry('450x450')//tanto faz se será o geometry ou o title primeiro
janela.mainloop()//deve ser o último a ser chamado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.