从函数中更改全局变量

时间:2016-07-05 20:40:49

标签: python tkinter

背景: 我的目标是制作一个计时器来跟踪工作时间后发送的时间页。我将原始页面文本粘贴到一个框中,按一个按钮,它将解析这个以获取票证,标题,分析师和他们的号码,以及启动计时器以跟踪何时重新加载/升级。我们的想法是使用网格和5组变量创建5个可能的行来同时抛出票据信息,最好只使用一个选择第一个可用行的输入框/按钮组合。

我目前停留在如何设置字符串变量(甚至访问未解析信息的文本框内容)以显示将用于按下按钮的功能中的故障单信息。我在函数中引用任何一个未定义的错误,即使在全局声明它们时(我甚至不知道如果/如何使用tkinter小部件并使用.get()?)。

我有一种感觉,我可能正在做一些根本错误的事情,但是我在如何完成这项任务时遇到了很多麻烦。

主要应用程序:

from tkinter import *
from newPageEntry import *

#Create window
master = Tk()
master.title('SD Page Time')
master.configure(bg='White')

#Page entry text box setup
newPageTextBox = Entry(master)
newPageTextBox.grid(row=6, column=6)

#page entry button
newPageButton1 = Button(master, text="New Page", width=10, command=newPageEntry(newPageTextBox.get())).grid(row=6, column=7)

#Grid Variables Setup
ticketNumberString1 = StringVar()
analystNameString1 = StringVar()
analystPhoneString1 = StringVar()
ticketTitleString1 = StringVar()

ticketNumberString2 = StringVar()
analystNameString2 = StringVar()
analystPhoneString2 = StringVar()
ticketTitleString2 = StringVar()

ticketNumberString3 = StringVar()
analystNameString3 = StringVar()
analystPhoneString3 = StringVar()
ticketTitleString3 = StringVar()

ticketNumberString4 = StringVar()
analystNameString4 = StringVar()
analystPhoneString4 = StringVar()
ticketTitleString4 = StringVar()

ticketNumberString5 = StringVar()
analystNameString5 = StringVar()
analystPhoneString5 = StringVar()
ticketTitleString5 = StringVar()

新页面模块:

from telalertParse import *
# import timer once made

#gets telalert page raw text from text box, enters it into parser. 
#inserts [ticketNumber, analystName, analystNumber, title] into the first available row, clears box
def newPageEntry(telalertPage):
    global newPageTextBox
    newPageTextBox.delete(0, END)
    telalertParseReturn = telalertParse(telalertPage)

    ticketNumber = telalertParseReturn[0]
    analystName = telalertParseReturn[1]
    analystNumber = telalertParseReturn[2]
    title = telalertParseReturn[3]

    if ticketNumberString1.get() != '':
        ticketNumberString1.set(ticketNumber)
        analystNameString1.set(analystName)
        analystPhoneString1.set(analystNumber)
        ticketTitleString1.set(title)
        #Start Timer

    elif ticketNumberString2.get() != '':
        ticketNumberString2.set(ticketNumber)
        analystNameString2.set(analystName)
        analystPhoneString2.set(analystNumber)
        ticketTitleString2.set(title)
        #Start Timer

    elif ticketNumberString3.get() != '':
        ticketNumberString3.set(ticketNumber)
        analystNameString3.set(analystName)
        analystPhoneString3.set(analystNumber)
        ticketTitleString3.set(title)
        #Start Timer

    elif ticketNumberString4.get() != '':
        ticketNumberString4.set(ticketNumber)
        analystNameString4.set(analystName)
        analystPhoneString4.set(analystNumber)
        ticketTitleString4.set(title)
        #Start Timer

    elif ticketNumberString5.get() != '':
        ticketNumberString5.set(ticketNumber)
        analystNameString5.set(analystName)
        analystPhoneString5.set(analystNumber)
        ticketTitleString5.set(title)
        #Start Timer
    else:
        print('Too Many Pages!')

0 个答案:

没有答案