标签上没有显示文本

2024-09-30 18:25:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python3.6.4和tkinter为编程赋值制作一个GUI程序,它基本上随机生成值,将它们与现有字符串组合,并在一堆标签上显示所有值

我的问题是,文本根本没有显示在标签上。标签本身的格式基于文本,但没有可见的文本

我已经到处找过有类似问题的人了,但是我一点运气都没有

请注意,我对这一切都是非常陌生的,我的代码可能是一个巨大的混乱。我为可能诱发脑瘤的密码提前道歉

def new_win():

    import tkinter as tk

    newwin = Tk()

    def runBreif():

        global year
        global market
        global location
        global minCompetitiveness

        yearD = str(['Year:', year])
        marketD = ['Market:', market]
        locationD = ['Location:', location]
        minCompetitivenessD = str(['Minimum score:', minCompetitiveness])

        def title():
            varTitle = StringVar()
            TileL = Label( newwin, textvariable = varTitle, relief = RAISED, font = 'roman 25 bold', width = 80, height = 3, bg = 'light grey', fg = 'red')
            #Setting message
            varTitle.set('Your task:')
            #Packing welcome message
            TileL.pack()
            print('Your task:')

        def yearDisplay():
            global year
            varY = StringVar()
            yearL = Label( newwin, textvariable = varY, relief = RAISED, font = 'arial 15 bold', width = 80, height = 3, bg = 'light grey')
            #Setting message
            varY.set(yearD)
            #Packing welcome message
            yearL.pack()
            print(yearD)

        def marketDisplay():
            global market
            varM = StringVar()
            marketL = Label( newwin, textvariable = varM, relief = RAISED, font = 'arial 15 bold', width = 80, height = 3, bg = 'light grey')
            #Setting message
            varM.set(marketD)
            #Packing welcome message
            marketL.pack()
            print(marketD)

        def locationDisplay():
            global location
            varL = StringVar()
            locationL = Label( newwin, textvariable = varL, relief = RAISED, font = 'arial 15 bold', width = 80, height = 3, bg = 'light grey')
            #Setting message
            varL.set(locationD)
            #Packing welcome message
            locationL.pack()
            print(locationD)

        def scoreDisplay():
            global minCompetitiveness
            varS = StringVar()
            scoreL = Label( newwin, textvariable = varS, relief = RAISED, font = 'arial 15 bold', width = 80, height = 3, bg = 'light grey')
            #Setting message
            varS.set(minCompetitivenessD)
            #Packing welcome message
            scoreL.pack()
            print(minCompetitivenessD)

        def BreifDisc():
            global breif
            varB = StringVar()
            breifL = Label( newwin, textvariable = varB, relief = RAISED, font = 'arial 10 bold', width = 80, height = 3, bg = 'light grey')
            #Setting message
            varB.set(breif())
            #Packing welcome message
            breifL.pack()
            #print(breif())

这是我的代码中格式化标签的部分。忽略print()s,它们只是让我检查代码是否正确地生成了变量(实际上是这样)

我会张贴我的输出和问题的图像,但显然我没有足够的声誉这样做

如果你想看我的完整程序,这里有一个dropbox链接 https://www.dropbox.com/preview/Saves/autoinspiration_V_0.06_ALPHA.py?role=personal


Tags: messagedefwidthgloballabelbgprintfont