文字未显示在标签上

时间:2019-06-10 13:03:02

标签: python python-3.x user-interface tkinter

我正在使用python 3.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(),这些只是我要检查的代码是否正确生成了变量(是)。

我会发布我的输出和相关问题的图片,但是显然我没有这样做的声誉。

如果您希望看到它,这里是一个指向我完整程序的保管箱链接 https://www.dropbox.com/preview/Saves/autoinspiration_V_0.06_ALPHA.py?role=personal

0 个答案:

没有答案