簡體   English   中英

按鈕文本和顏色不會出現在Tkinter程序中

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

該程序在運行window或ubuntu的其他計算機上運行正常,但文本不會顯示在按鈕上。 這是一段較長代碼的片段:

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

我們期待像“開始”和“退出”這樣的詞語。

我們只希望按鈕的顏色與文本一起顯示

我不確定問題是什么。 我拿出了不必要的進口貨,跑了

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

這為我創造了:

預期的GUI

這是你指定的顏色......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM