我根本无法看到eventCards是如何初始化的。有人能告诉我吗?
ReferenceError:无法访问未初始化的变量。 7:26行
import tkinter as tk
def deposit():
amount_display = tk.Text(root, width=5, height=5)
amount_display.grid(column=7, row=2)
response_text = 'You deposited ${}'.format(deposit_entry.get())
amount_display.insert(tk.END, response_text)
def withdraw():
pass
root = tk.Tk()
root.geometry('500x300')
root.title('Savings App')
# Labels
tk.Label(root, text='Deposit').grid(column=2, row=3)
tk.Label(root, text='Withdraw').grid(column=6, row=3)
# Entries
deposit_entry = tk.Entry(root)
deposit_entry.grid(column=2, row=4)
withdraw_entry = tk.Entry(root)
withdraw_entry.grid(column=6, row=4)
# Buttons
tk.Button(master=root, text='Deposit', command=deposit).grid(column=2, row=5)
tk.Button(master=root, text='Withdraw', command=withdraw).grid(column=6, row=5)
root.mainloop()
答案 0 :(得分:2)
对于class
变量,您需要在使用之前定义class
。只需将类定义提升到顶部即可:
class Deck {
constructor(cards) {
this.cards = cards;
this.deck = shuffle(cards);
}
shuffle(array) {
...
}
drawTopCard() {
...
}
}
var eventCards = [
'Do1',
'Do2',
'Do3',
'Do4'
];
var eventDeck = new Deck(eventCards);
请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes