Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Sizegrip controls in Python

Shulou Source: shulou.com Published: 2022-06-02 07:56:56 10月05日 Update

This article shows you how to use the Sizegrip control in Python, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The first is to build the main window.

Root = Tk () root.title ('Tkinter Sizegrip Demo V1.0')

Screen_w = root.winfo_screenwidth () screen_h = root.winfo_screenheight () root.maxsize (width=screen_w, height=screen_h) rw = int (screen_w / 2) rh = int (screen_h / 2) root.geometry ('{} x {} + {: G} + {: G} '.format (rw, rh, rw / 2, rh / 2))

In addition to specifying the window title, the code also centers the window. Next is to build the exit menu:

Top_menu = Menu (root) root.config (menu=top_menu)

File_menu = Menu (top_menu, tearoff=False) top_menu.add_cascade (label='File', menu=file_menu) file_menu.add_command (label= "Exit", command=root.quit)

For ease of management, first generate a Frame control that manages the editor control:

Edit_area = Frame (root) edit_area.grid (row=1, column=0)

The Text control is also resized when it is generated. Because the height and width of Text are specified in characters, it takes a lot of trouble. If you do not resize the Text, when the size of the root window reaches a certain value, the Text will no longer follow the size of the window.

# create text widget.

Font= Font (family='Arial', size=15), text = Text (edit_area, font=font, height=80, wrap=NONE) text.config (width=int (text ['width'] * screen_w / text.winfo_reqwidth ()), height=int (text [' height'] * screen_h / text.winfo_reqheight ()) text.grid (row=0, column=0, sticky='nsew')

The result of text.config execution is to resize the Text control to the same size as the screen. Next, it is standard practice to build scroll bar controls.

Scroll_ty = Scrollbar (edit_area, orient=VERTICAL, command=text.yview) scroll_ty.grid (row=0, column=1, sticky=N+S) text ['yscrollcommand'] = scroll_ty.set

Scroll_tx = Scrollbar (edit_area, orient=HORIZONTAL, command=text.xview) scroll_tx.grid (row=1, column=0, sticky=E+W) text ['xscrollcommand'] = scroll_tx.set

Sizegrip itself is simple:

Sizegrip (edit_area) .grid (row=1, column=1) the above is how to use Sizegrip controls in Python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Controls dimensions next content size skills knowledge generation management adjustment conciseness brevity code practices units and at the same time twists and turns characters width that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS NVidia vpn Huawei