仅作为记录,大佬请跳过。
文章目录
listbox放大字体
用font=("Helvetica",20)
lb = tkinter.Listbox(root, listvariable=lbVal,font=("Helvetica",20))
参考
展示
tkinter的button的relief
按钮的样式
参考
又一参考: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()
参考
感谢大佬博主文章:传送门