<p>必须使<code>DeliveryInterface</code>全局:</p>
<pre><code> def InputScreen():
global DeliveryInterface
DeliveryInterface = tkinter.Tk() #creates the interface for the input screen
DeliveryInterface.title('Input New Data') #gives the new window a title
DeliveryInterface.geometry('400x500') #sets the default size of the window as 400 x 500
DeliveryInterface.maxsize(400, 500) #sets the maximum size of the interface as 400 x 500
DeliveryInterface.configure(background='#0092FF') #sets the background colour of the inteface to the light blue as seen in the main menu interface
(.......)
StockIDLabel = tkinter.Label(DeliveryInterface, text='Stock ID', font=('Helvetica', 16)) # creates a label that tells the user that the next box is associated with the stock id
StockIDLabel.place(x=30, y=60, height=22, width=200)
StockID_entry = tkinter.Entry(DeliveryInterface, font=('Helvetica', 16)) # creates the entry box for the stock ID
StockID_entry.place(x=250, y=60, height=22, width=100)
(...........)
def addingNewStock():
StockID = 0 #Initialises the stock ID
StockID = DeliveryInterface.StockID_entry.get() #intended to get the data from the entrybox, however, i get an error message say that DeliveryInterface hasnt been defined
print (StockID) #prints the stockID so that i now if the variable has been changed.
</code></pre>
<p>另一个选择是使用python3的<code>nonlocal</code>关键字。你知道吗</p>