Python tkinter window size winfo1/3/2024 Used to display static text, like Label, but allows for multiple lines, text wrapping, and maintaining aspect ratios.ĭrop-down (or pop-up) menu that allows users to select one option from several options.Ĭontainer for one or more widgets split into multiple "panes." These panes can be resized by the user by dragging the serparator line(s) (known as "sashes"). Can be used to create the always-shown "menu bar" popular in many GUI applications. Used to create menus and submenus within an interface. The user can choose (highlight) one or more options. Used to display text or an image that may not be edited by the user.Ī rectangular area that contains other widgets, but unlike a Frame, a border and label may be added to help group widgets together.ĭisplays a list of text alternatives. A Frame can be useful for grouping other widgets together in a complex layout. For entering multiple lines, use the Text widget.Ī container for other widgets. Also known as a "checkbox."Īrea that allows the user to enter one line of text. General purpose widget that can display simple graphics or provide an area to implement a custom widget.Īllows a user to read and select between two distinct values (e.g. In this example, root is at the top of our hierarchy followed by our label object under that.Ĭlickable area with text that calls an associated function whenever the user clicks in the area. When it comes to creating GUIs with Tkinter, it's generally a good idea to create your widgets first and then lay out your widgets together within the same hierarchy. We also set the default message in the label to be the classic "Hello, World!" In this example, we want the root window to be the parent object of our label (i.e. Notice that when we create any widget, we must pass it a reference to its parent object (the object that will contain our new widget). Label = tk.Label(root, text="Hello, World!") Here, we create a Label widget: language:python Widgets can include things like buttons, labels, text entry boxes, and so on. In this window, we can add various control elements, known as widgets. For example, we can change the name in the title bar by calling the title method in the root window: language:python This handle allows us to put other things in the window and reconfigure it (e.g. We save a handle to this window in the variable root. This automatically creates a graphical window with the necessary title bar, minimize, maximize, and close buttons (the size and location of these are based on your operating system's preferences). Next, we create a root window by calling Tkinter's constructor, tk.Tk(). In a larger application, you would need to keep track of all these global variables in your head, which can be quite difficult! For example, Tkinter has a variable named E (which we'll see in a later example), and it's much easier to remember that you mean Tkinter's version of E (rather than E from another module) by having to write tk.E. you would only need to type Tk() instead of tk.Tk()), it has the downside of cluttering your global workspace. While this might make typing easier (e.g. This says to import all classes, functions, and variables from the Tkinter package into the global space. In other Tkinter guides, you might see the import written as from tkinter import *. We do this to save us some typing in the rest of the code: we just need to type tk instead of tkinter. We import the Tkinter module and shorten the name to tk. Let's break down the relatively simple program.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |