python tkinter main window

Question:

I was trying to open a code with pycharm and the following lines are the begining . but it doesn’t open any window . what should I do ?

import tkinter
mainwindow=tkinter.Tk()
mainwindow.title("Calculator")
mainwindow.geometry('480x240')
buttonOne= tkinter.Button(mainwindow,text='1')

it runs and instantly closes without opening any window

Asked By: arihs

||

Answers:

In order to make sure the window doesn’t close you need the mainloop function.

import tkinter
mainwindow=tkinter.Tk()
mainwindow.title("Calculator")
mainwindow.geometry('480x240')
buttonOne= tkinter.Button(mainwindow,text='1')
tkinter.mainloop()
Answered By: Kutay Kılıç
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.