Tkinter checkbutton - text won't show up

試著忘記壹切 提交于 2020-01-22 02:47:28

问题


When I try to use a checkbutton it works fine but the text won't appear. I can't understand why. Below is my code

from tkinter import *
a = Tk()
var1 = IntVar()
Checkbutton(a, text="checkbutton", variable=var1, fg='blue').grid(row=0,sticky=W)
a.mainloop()

The checkbox appears but the text alongside does not


回答1:


Try using themed tk (ttk) checkbutton widget:

import tkinter as tk
from tkinter import ttk

a = tk.Tk()

var1 = tk.IntVar()

check_btn = ttk.Checkbutton(a, text="checkbutton", variable=var1)
check_btn.grid(row=1,sticky='w')

# set foreground color to blue
check_btn_style = ttk.Style()
check_btn_style.configure('TCheckbutton', foreground='blue')

a.mainloop()


来源:https://stackoverflow.com/questions/59338948/tkinter-checkbutton-text-wont-show-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!