Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window doesn't appear using Tkinter

This is the file I launch with python :

from Tkinter import *

# Esempio di GUI

def main():
    w1 = Tk()
    w1.title("Finestra 1")
    f1 = Frame(w1)
    f1.pack()
    w1.mainloop()

main()

The program is in execution, but I don't see any window appearing. I have to close the terminal window to stop, I don't get why.

like image 706
Ramy Al Zuhouri Avatar asked Jan 28 '12 21:01

Ramy Al Zuhouri


People also ask

Why Tkinter is not working?

The easiest way to fix this problem is by upgrading your python to use python 3. If upgrading python is not an option, you only need to rename your imports to use Tkinter (uppercase) instead of tkinter (lowercase). Output: As a result, this window proves that your python installation includes the Tkinter module.

How do I run a Tkinter window?

Tkinter ProgrammingImport the Tkinter module. Create the GUI application main window. Add one or more of the above-mentioned widgets to the GUI application. Enter the main event loop to take action against each event triggered by the user.

How do you display the window at the center of the screen in Tkinter?

In order to place a tkinter window at the center of the screen, we can use the PlaceWindow method in which we can pass the toplevel window as an argument and add it into the center. We can also set the window to its center programmatically by defining its geometry.

How do I create a popup window in Tkinter?

Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.


1 Answers

Give the frame a width and height:

from Tkinter import *

# Esempio di GUI

def main():
    w1=Tk()
    w1.title("Finestra 1")
    # Width, height in pixels
    f1=Frame(w1, height=50, width=50)
    f1.pack()
    w1.mainloop()

main()
like image 119
Michael Berkowski Avatar answered Oct 05 '22 04:10

Michael Berkowski