简体   繁体   中英

Tkinter checkbutton - text won't show up

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

这是我运行时显示的内容

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM