tkinter的一些控件设置——listbox放大字体

仅作为记录,大佬请跳过。

listbox放大字体

font=("Helvetica",20)

lb = tkinter.Listbox(root, listvariable=lbVal,font=("Helvetica",20))

参考

传送门

展示

在这里插入图片描述

tkinter的button的relief

按钮的样式

在这里插入图片描述

参考

传送门tkinter入门-按钮的基本属性

又一参考:Label控件、Frame控件、Button控件的完整参数和所有方法及详细用法

在这里插入图片描述

tkinter的button的cursor

设置鼠标停留的样式

cursor='hand2'

在这里插入图片描述
参考

传送门

在这里插入图片描述

tkinter的button的字体变大,形状也变大的解决

实例

可直接运行

import tkinter as tk

MyWindow = tk.Tk()
MyWindow.geometry("500x550")

#create LabelFrame (200x200)
label = tk.LabelFrame(MyWindow, width=100, height=100)

#grid manager to set label localization
label.grid(row=0, column=0)

#label row and column configure: first argument is col or row id
label.grid_rowconfigure(0, weight=1)
label.grid_columnconfigure(0, weight=1)

#cancel propagation
label.grid_propagate(False)

#Create button and set it localization. You can change it font without changing size of button, but if You set too big not whole will be visible
button = tk.Button(label, text="Hello!", font=('Helvetica', '20'))

#Use sticky to button took up the whole label area
button.grid(row=0, column=0, sticky='nesw')

MyWindow.mainloop()

参考

传送门

博主应用程序

'''设置button所在的label的函数——原因:tkinter的button的字体变大,形状也变大'''
def label_out_btn(w,h,co_x,co_y):
    label_btn = tkinter.LabelFrame(root, width=w, height=h)
    label_btn.place(x=co_x, y=co_y)
    label_btn.grid_rowconfigure(0, weight=1)
    label_btn.grid_columnconfigure(0, weight=1)
    label_btn.grid_propagate(False)
    return label_btn
label_confirm=label_out_btn(100,50,256*3+60-50,16*3+260)
clickBtn=tkinter.Button(label_confirm,text='确 认',command=getListBoxValue,font=('microsoft yahei', 12),relief='flat',cursor='hand2')
clickBtn.grid(row=0, column=0, sticky='nesw')
# clickBtn=tkinter.Button(root,text='确 认',width=8,height=2,command=getListBoxValue,font=('microsoft yahei', 10),relief='ridge',cursor='hand2')
# clickBtn.place(x=256*3+60-50,y=16*3+260)

展示

在这里插入图片描述

tkinter的列表框大小设置

height=20

默认是10行

展示

lb = tkinter.Listbox(root, listvariable=lbVal,font=("Helvetica",15),height=20)

在这里插入图片描述

参考

传送门

在这里插入图片描述

数据类型

str (eval(str)) →list【其中的()以各个tuple的形式组成]

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

listbox的滚动条

实例,可直接运行

import tkinter

root = tkinter.Tk()

sc = tkinter.Scrollbar(root)
sc.pack(side=tkinter.RIGHT, fill=tkinter.Y)

# 列表动,滚动条跟着动
lb = tkinter.Listbox(root, yscrollcommand=sc.set)
for i in range(50):
    lb.insert(tkinter.END, "列表 " + str(i))
lb.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)
# 滚动条动,列表跟着动
sc.config(command=lb.yview)

root.mainloop()

在这里插入图片描述
参考

感谢大佬博主文章:传送门

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值