按钮文本和颜色未出现在Tkinter程序上

时间:2019-05-08 21:21:05

标签: python macos tkinter

该程序在运行window或ubuntu的其他计算机上运行良好,但文本不会显示在按钮上。这是一段较长的代码:

*** CAPTURED TEXT***:
Running LogProcessor tests...
Inside test_var_value
F
======================================================================
FAIL: test_var_value (__main__.LogProcessorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 16, in test_var_value
    self.assertEqual(self.var, 'that value')
AssertionError: 'this value' != 'that value'
- this value
?   ^^
+ that value
?   ^^


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)

我们希望显示“开始”和“退出”之类的词。

我们只希望按钮的颜色与文本一起显示

1 个答案:

答案 0 :(得分:0)

我不确定问题是什么。我拿出不必要的进口,然后跑了

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

哪个为我创造了

expected GUI

这是您指定的颜色...