Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Tkinter Frame Widget

Python Tkinter Frame Widget

Python GUI Programming Python GUI Programming

The Python Tkinter Frame widget displays a rectangular area on the screen and is mostly used as a container.

Syntax

The syntax format is as follows:


w = Frame ( master, option, ... )
No. Options & Description
1

bg

The background color of the frame

2

bd

The size of the frame, defaulting to 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

The height of the frame, defaulting to 0.

5

highlightbackground

The color of the highlight border when the frame does not have focus; the default is specified by the system.

6

highlightcolor

The color of the highlight border when the frame has focus

7

highlightthickness

Specify the width of the highlight border, defaulting to 0 (no highlight border)

8

relief

Border style, with options: FLAT, SUNKEN, RAISED, GROOVE, RIDGE. The default is FLAT.

9

width

Set the frame width, defaulting to 0.

10

takefocus

Specify whether the widget accepts input focus (the user can move focus to it with the tab key), defaulting to false.

Example

#!/usr/bin/python

-- coding: UTF-8 --

Use Tkinter in python2

from

Tkinter

import

Use tkinter in python3

#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:

Python GUI Programming Python GUI Programming