python Tkinter的一些记录

[color=red][b]1. Label里面的文本对齐方式[/b][/color]:[url]http://www.hiadmin.org/code/python_tkinter_label[/url]
Label(root, text="www.hiadmin.org",bg="red",width=20,height=2, wraplength=80,anchor="w",[color=red]anchor="w",justify="left"[/color]).pack()

[color=red][b]2. Listbox + Scrollbar[/b][/color]
listbox = Listbox(root, width=c1Width, selectmode=MULTIPLE)
listbox.grid(row=10, column=1)
listboxScrollbar = Scrollbar(root)
listboxScrollbar.grid(row=10, column=1, sticky=N + S + E)
listbox['yscrollcommand'] = listboxScrollbar.set
listboxScrollbar['command'] = listbox.yview

使用grid布局,listbox和scrollbar占同一个单元格,
再使用sticky=N + S + E制定scrollbar的位置是:北+南+东(就是说从北到南,就是垂直占满;靠右边,就是说居右)
让两个空间产生互动效果
[b][color=darkblue]listbox['yscrollcommand'] = listboxScrollbar.set
listboxScrollbar['command'] = listbox.yview[/color][/b]

[color=red][b]3. 窗口居中对齐[/b][/color]
from Tkinter import *
def center_window(w=300, h=200):
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root = Tk()
center_window(500, 300)
root.mainloop()


[color=red][b]4. Text + Scollbar[/b][/color]
    messageText=Text(root, height=15,width=122, fg="red")

vLabelScrollbar = Scrollbar(root)
vLabelScrollbar.grid(row=12, column=4, sticky=N + S + E)
hLabelScrollbar = Scrollbar(root, orient=HORIZONTAL)
hLabelScrollbar.grid(row=13, column=0, columnspan=4, sticky=N + W + E)
messageText.grid(row=12,column=0, columnspan=4)

vLabelScrollbar['command'] = messageText.yview
messageText.config(yscrollcommand=vLabelScrollbar.set)
hLabelScrollbar['command'] = messageText.xview
messageText.config(xscrollcommand=hLabelScrollbar.set)


[color=red][b]5. Text设定文本[/b][/color],Text居然木有textvariable
t = Text(root) 
t.pack()
t.insert(1.0,'0123456789')
t.insert(END,'jcodeer')
t.focus_force()

使用focus_force()来使光标在文本后面

[color=red][b]6. 禁止Tk()生成的root改变尺寸[/b][/color]: root.resizable(0,0)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值