首页 > 解决方案 > 如何在 Tkinter 中更改按钮文本的大小

问题描述

import tkinter as tk

HEIGHT = 950
WIDTH = 650

root=tk.Tk()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

frame = tk.Frame(root, bg='#80c1ff')
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')

button = tk.Button(frame, text="Credit Score Checker", font=20)
button.place(relx=-0, relheight=1, relwidth=0.27)

button = tk.Button(frame, text="Financial Advisor", font=20)
button.place(relx=0.25, relheight=1, relwidth=0.27)

button = tk.Button(frame, text="Insurance Planner", font=20)
button.place(relx=0.5, relheight=1, relwidth=0.27)

button = tk.Button(frame, text="Goal Setter", font=20)
button.place(relx=0.75, relheight=1, relwidth=0.26)

lower_frame = tk.Frame(root, bg='#80c1ff', bd=10)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')

label = tk.Label(lower_frame, text="Summary of finances", bg='grey')
label.place(relx=0.5, rely=0, anchor='n', relwidth=0.9, relheight=1)

root.mainloop()

标签: tkinter

解决方案


而不是 font = 20 可以使用

font = ("Helvetica",20,"bold")
#font=(font-family , font-size , "bold"/"italic")

您还可以执行以下操作

font = "Helvetica 20 bold"

对于 tkinter 的笔记,您可以访问 https://mycodenotein.netlify.app


推荐阅读