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.
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.
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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With