300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > tkinter的一些控件设置——listbox放大字体

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

时间:2021-02-27 14:29:45

相关推荐

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

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

文章目录

listbox放大字体tkinter的button的relieftkinter的button的cursortkinter的button的字体变大,形状也变大的解决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 tkMyWindow = tk.Tk()MyWindow.geometry("500x550")#create LabelFrame (200x200)label = tk.LabelFrame(MyWindow, width=100, height=100)#grid manager to set label localizationlabel.grid(row=0, column=0)#label row and column configure: first argument is col or row idlabel.grid_rowconfigure(0, weight=1)label.grid_columnconfigure(0, weight=1)#cancel propagationlabel.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 visiblebutton = tk.Button(label, text="Hello!", font=('Helvetica', '20'))#Use sticky to button took up the whole label areabutton.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_btnlabel_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 tkinterroot = 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()

参考

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。