python模块tkinter的常用控件2

demo
原文

1. Message

1
2
3
4
5
6
# .config(**options)
message = tkinter.Message(
root,
text = "message is similar to label without image"
)
message.pack()

2. OptionMenu

1
2
3
4
5
var = tkinter.StringVar(root)
optionMenu = tkinter.OptionMenu(root, var, "one", "two", "three")
optionMenu.pack()
# print (optionMenu.keys())
# print (dir(optionMenu))

3. LabelFrame

1
2
3
4
5
6
7
8
9
10
group = tkinter.LabelFrame(
root,
text = "group box",
padx = 10,
pady = 10
).pack()
entry = tkinter.Entry(
root
).pack()
# as a view group

4. Scale

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
s = tkinter.Scale( # a slider
root,
from_ = 10,
to = 20,
orient = "vertical", # horizontal
resolution = 2 # the step ,use -1 to disable rounding.
# digits =
# label =
# repeatinterval = # Default value is 100.
# showvalue =
# sliderlength =
# sliderrelief =
# tickinterval =
# troughcolor =
).pack()
# coords(value=None) # Gets the screen coordinate corresponding to the given scale value.
# get() # Gets the current scale value.
# identify(x, y) # Checks if an active part of the scale is at the given screen location.
# set(value)

5. Scrollbar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# The Scrollbar widget is almost always used in conjunction with a Listbox, Canvas, or Text widget. Horizontal scrollbars can also be used with the Entry widget.
# To connect a vertical scrollbar to such a widget, you have to do two things:
# Set the widget’s yscrollcommand callbacks to the set method of the scrollbar.
# Set the scrollbar’s command to the yview method of the widget.
sb = tkinter.Scrollbar(root)
sb.pack(side ="right",fill = "y")
lb = tkinter.Listbox(
root,
yscrollcommand = sb.set
)
sb.config(command = lb.yview)
for x in range(10,300,5):
lb.insert(0,x)
lb.pack(side = 'left',fill = "both")
#
# activate(element)
# elementborderwidth=
# jump =
# orient =
# repeatdelay =
# repeatinterval=
# troughcolor=
# delta(deltax, deltay)
# fraction(x, y)
# get()
# identify(x, y)
# set(lo, hi)

6. Spinbox

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Spinbox
sp = tkinter.Spinbox( # numner select
root,
from_ = 10,
to = 100,
# command =
# xscrollcommand = # Used to connect a spinbox field to a horizontal scrollbar. This option should be set to the set method of the corresponding scrollbar
)
sp.pack()
# Spinbox(root, values = (3,6,9))
# delete(first, last=None)
# get()
# icursor(index)
# identify(x, y)
# index(index)
# insert(index, text)
# invoke(element)
# scan_dragto(x)
# scan_mark(x)
# selection_adjust(index)
# selection_clear()
# selection_element(element=None)

7. Toplevel

1
2
3
4
5
6
7
# The Toplevel widget is used to display extra application windows, dialogs, and other “pop-up” windows.
tl = tkinter.Toplevel()
tl.title("top level")
lb = tkinter.Label(tl, text = "this is Toplevel lavel")
lb.pack()
btn = tkinter.Button(tl,text = "destroy",command = tl.destroy)
btn.pack()

8. tkMessageBox

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# The tkMessageBox module provides an interface to the message dialogs.
# tkMessageBox.function(title, message [, options]).
tkMessageBox.showwarning(
"Open file",
"Cannot open this file\n"
)
# showinfo
# showwarning
# showerror
# askquestion
# askokcancel
# askyesno
# askretrycancel
# Message Box Options
default # ABORT, RETRY, IGNORE, OK, CANCEL, YES, or NO
icon # ERROR, INFO, QUESTION, or WARNING
message (string)
parent (widget)
title (string)
type (constant) # ABORTRETRYIGNORE, OK, OKCANCEL, RETRYCANCEL, YESNO, or YESNOCANCEL.

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. 1. Message
  2. 2. 2. OptionMenu
  3. 3. 3. LabelFrame
  • 4. Scale
    1. 1. 5. Scrollbar
    2. 2. 6. Spinbox
    3. 3. 7. Toplevel
    4. 4. 8. tkMessageBox
  • ,