8/17/2023 0 Comments Tkinter winfo existsThe previous example without justify (default is centre) and padx looks like this: padx can be used to add additional horizontal padding around a text label. The "justify" parameter can be used to justify a text on the LEFT, RIGHT or CENTER. If you start this script, it will look like this using Ubuntu Linux with Gnome desktop: W1 = tk.Label(root, image=logo).pack(side="right")Įxplanation = """At present, only GIF and PPM/PGM Logo = tk.PhotoImage(file="python_logo_small.gif") The following example contains two labels, one with a text and the other one with an image. Our script will remain in the event loop until we close the window.Īs we have already mentioned, labels can contain text and images. The window won't appear until we enter the Tkinter event loop: The pack method tells Tk to fit the size of the window to the given text. W = tk.Label(root, text="Hello Tkinter!") The keyword parameter "text" specifies the text to be shown: So our Label widget is a child of the root widget. The first parameter of the Label call is the name of the parent window, in our case "root". The next line of code contains the Label widget. The root widget has to be created before any other widgets and there can only be one root widget. To initialize tkinter, we have to create a Tk root widget, which is a window with a title bar and other decoration provided by the window manager. In our example, we imported tkinter by renaming it into tk, which is the preferred way to do it: The tkinter module, containing the Tk toolkit, has always to be imported. Under Windows it appears in the Windows look and feel: If you run the command under the Gnome and Linux, the window the window will look like this: If we save the script under the name hello.py, we can start it like this using the command shell: Enjoying this page? We offer live Python training courses covering the content of this site.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |