简体   繁体   English

按钮文本和颜色不会出现在Tkinter程序中

[英]The button text and color does not appear on Tkinter program

The program works fine on other computers that run window's or ubuntu but the text won't show on the buttons. 该程序在运行window或ubuntu的其他计算机上运行正常,但文本不会显示在按钮上。 Here's a snippet of a longer code: 这是一段较长代码的片段:

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

We were expecting words like "start" and "exit" to show. 我们期待像“开始”和“退出”这样的词语。

We just want the colors of the buttons to show along with the text 我们只希望按钮的颜色与文本一起显示

I am not sure what the question is. 我不确定问题是什么。 I took out unnecessary imports, and ran 我拿出了不必要的进口货,跑了

from tkinter import *

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

Which creates for me: 这为我创造了:

预期的GUI

This is colored as you have specified... 这是你指定的颜色......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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