YouTip LogoYouTip

Python Tk Frame

# Python2.x Python Tkinter Frame Widget [![Image 4: Python GUI Programming](#) Python GUI Programming](#) The Python Tkinter Frame widget displays a rectangular area on the screen, often used as a container. ### Syntax The syntax format is as follows: w = Frame ( master, option, ... ) * master: The parent container of the frame. * options: Optional parameters, which are the settable attributes of the frame. These options can be set in key-value form, separated by commas. | No. | Options & Description | | --- | --- | | 1 | **bg** Background color of the frame. | | 2 | **bd** Size of the frame border, default is 2 pixels. | | 3 | **cursor** The shape of the cursor when the mouse moves over the frame. Can be set to arrow, circle, cross, plus, etc. | | 4 | **height** Height of the frame, default is 0. | | 5 | **highlightbackground** Color of the highlight border when the frame does not have focus, default is system-specified. | | 6 | **highlightcolor** Color of the highlight border when the frame has focus. | | 7 | **highlightthickness** Specifies the width of the highlight border, default is 0 (no highlight border). | | 8 | **relief** Border style. Options include: FLAT, SUNKEN, RAISED, GROOVE, RIDGE. Default is FLAT. | | 9 | **width** Sets the width of the frame, default is 0. | | 10 | **takefocus** Specifies whether the widget accepts input focus (users can transfer focus using the tab key), default is false. | ## Example #!/usr/bin/python# -*- coding: UTF-8 -*-# python2 uses Tkinter from Tkinter import * # python3 uses tkinter#from tkinter import *def say_hi(): print("hello ~ !")root = Tk()frame1 = Frame(root)frame2 = Frame(root)root.title("tkinter frame")label= Label(frame1,text="Label",justify=LEFT)label.pack(side=LEFT)hi_there = Button(frame2,text="say hi~",command=say_hi)hi_there.pack()frame1.pack(padx=1,pady=1)frame2.pack(padx=10,pady=10)root.mainloop() The test output is as follows: !(#) [![Image 6: Python GUI Programming](#) Python GUI Programming](#)
← Os ReadlinkOs Pathconf β†’