【发布时间】:2019-05-08 21:21:05
【问题描述】:
该程序在运行 windows 或 ubuntu 的其他计算机上运行良好,但文本不会显示在按钮上。这是一段较长代码的 sn-p:
from Tkinter import *
from math import atan
from math import log
import math
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
# --- function ---
def create_first_frame():
global root
global frame
# frame.destroy()
frame = Frame(bg="blue")
frame.pack()
label1 = Label(frame, text="hello!", fg="white", bg="blue", font="normal 30")
label1.pack()
button1 = Button(frame, text="Enter", fg="white", bg="blue", font="normal 20")
button1.pack()
button2 = Button(frame, text="Exit", font="normal", fg="white", bg="red", command=root.destroy)
button2.pack(side=LEFT)
root = Tk()
create_first_frame()
root.mainloop()
我们期待显示“开始”和“退出”等词。
我们只希望按钮的颜色与文本一起显示
【问题讨论】:
-
遗憾的是,Tkinter Buttons 在 macOS 上没有太大的灵活性,您可以更改
fg但无法更改bg。这是因为 macOS ui 更改的限制和访问受限。看到这个post。