Python Forum
[Tkinter] question for a tkinter dialog box - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] question for a tkinter dialog box (/thread-34718.html)



question for a tkinter dialog box - RobertAlvarez424 - Aug-24-2021

import tkinter as tk

root = tk.Tk()
logo = tk.PhotoImage(file="python_logo_small.gif")

w1 = tk.Label(root, image=logo).pack(side="right")

explanation = """At present, only GIF and PPM/PGM
formats are supported, but an interface 
exists to allow additional image file
formats to be added easily."""

w2 = tk.Label(root,
              justify=tk.LEFT,
              padx = 10,
              text=explanation).pack(side="left")
root.mainloop()
new to python and tkinter , here a sample code I got in this tutor for tkinter .

So between root = tk.Tk() and root.mainloop() is the code for this dialog box.
My question is w1 and w2 . These are defined but do not understand how they are called to be used in root.mainloop() ?


RE: question for a tkinter dialog box - deanhystad - Aug-25-2021

You don't have a dialog box. You have a toplevel window.

There are commands for making different kinds of standard dialog boxes.

https://docs.python.org/3/library/dialog.html

Or you can make a custom dialog box:

https://code-maven.com/slides/python/tk-customized-simple-dialog

As an aside, you do not have w1 and w2. w1 and w2 are both None because that is the value returned by pack().

If you are asking how widgets appear in windows, that happens when the window is drawn. When you call root.mainloop() the first thing it does is draw the root window. Because you packed two labels in the root window, the labels are positioned and the root window grows to accommodate. If you had buttons or other interactive controls the root.mainloop() would process button and key press events.


RE: question for a tkinter dialog box - RobertAlvarez424 - Aug-25-2021

deanhystad, thanks for the reply
I been using POWERBASIC for a long time. Hope to duplicate everything to python. I have a long way to go. Python does not have good support for printing to printer so will use powerbasic for that. dll or exe.