nfig(bg="skyblue") # specify background color Root.maxsize(900, 600) # specify the max size the window can expand to Root.title("Basic GUI Layout") # title of the GUI window Be sure to focus on the row numbers below and see if their order makes sense. Now, let's take a quick look at adding a frame within the larger frame. Of course, you can also change the color of the Frame widget.Īll of the white is the frame. The background of the root window (sky blue) has been changed in line 5 in order to see the new frame (white). The other two parameters, padx and pady, specify the amount of padding around the widget in pixels.Ĭongrats! You have just created a simple frame. So the frame up above is in (row 0, column 0). We can assign different widgets in the window by specifying the values. Each "cell" has a row number and a column number. You can think of grid like an Excel spreadsheet. Next, we place left_frame in the main window using grid(). Grid is another layout method in Tkinter for organizing widgets. For example, if you display a small label inside the frame, then the frame will adjust to the label's size. It is important to note that the frames will resize to whatever has been put inside of them. We set left_frame as part of the root window. To add a frame into the root window, create a Frame1 widget as seen in line 8. Here we import Tkinter and all its functions, and set up the root window in lines 3-5. Left_frame = Frame(root, width=200, height=400) Nesting frames is even an option if needed. Frames are like boxes or mini-windows within the parent window - self-contained areas that each contain their own grids, so adding widgets to them is super easy. Organizing the GUI is made possible and easier with the Frame widget. Underneath that is a menu to select the basic tools or filters for editing the image. On the upper-left side of the GUI, a small label is used to see keep track of what the original image looked like for reference. A large area of the GUI will need to be devoted to the photograph. The left displays various tools and on the right is the image.įor this tutorial, let's build the foundation for what could be a photo editing application. Planning before we get started can help us think about where our widgets and frames will go.īasic design for the photo editor. Plan The Layoutīelow is a simple idea for what kind of window we will make in this tutorial. But if you have a project that you really want to make, then having a plan for where things go in the window will be more helpful in the long run. Of course, playing around with the functions and different widgets in Tkinter is one way to get started. Rather than teaching about buttons or other widgets just yet, let's get started with thinking about our interface and how to arrange objects in the window.īy the end of this tutorial you will learn how to create a simple and structured layout using the Frame widget, Tkinter and Python 3. However, I found that the layout of the window needed some work as boxes and images didn't look very organized. Previously, we talked about the basics of getting started with Tkinter - creating the window, and creating a Label to display text or images. Today's tutorial might be a short, but very important, one when it comes to making a GUI: the layout.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |