当我尝试更改教师的代码以创建新对话框时,shell始终显示NameDialog object has no attribute _column_enter
。
然而,我的老师的代码可以工作,所以我想知道,让我的代码无法工作有什么不同:
import tkinter
Font=('Helvetica', 14)
class User_design:
def __init__(self):
self._root_window=tkinter.Tk()
start_button=tkinter.Button(
master=self._root_window, text='click there to start.',
font=Font, command=self._get_start)
start_button.grid(
row = 0, column = 0, padx = 10, pady = 10,
sticky = tkinter.S)
self._greeting_text = tkinter.StringVar()
self._greeting_text.set('Not begin')
greeting_label = tkinter.Label(
master = self._root_window, textvariable = self._greeting_text,
font = Font)
greeting_label.grid(
row = 1, column = 0, padx = 10, pady = 10,
sticky = tkinter.N)
self._root_window.rowconfigure(0, weight = 1)
self._root_window.rowconfigure(1, weight = 1)
self._root_window.columnconfigure(0, weight = 1)
def start(self) -> None:
self._root_window.mainloop()
def _get_start(self):
dialog = NameDialog()
dialog.show()
if dialog.was_ok_clicked():
column=dialog.get_column()
row=dialog.get_row()
turn=dialog.get_turn()
top_left=dialog.get_top_left()
win_method=dialog.get_win_method()
class NameDialog:
def __init__(self):
self._dialog_window = tkinter.Toplevel()
#column_label
column_label=tkinter.Label(
master=self._dialog_window, text='How many columns?',
font=Font)
column_label.grid(
row=0, column=0, padx=10,pady=10, sticky=tkinter.W)
self._column_entry = tkinter.Entry(
master = self._dialog_window, width = 20, font = Font)
self._column_enter.grid(
row=0, column=1, padx=10,pady=10, sticky=tkinter.W)
#row_input
row_input=tkinter.Label(
master=self._dialog_window, text='How many rows?',
font=Font)
row_input.grid(
row=1, column=0, padx=10,pady=10, sticky=tkinter.W)
self._row_entry = tkinter.Entry(
master = self._dialog_window, width = 20, font = Font)
self._row_enter.grid(
row=1, column=1, padx=10,pady=10, sticky=tkinter.W)
#turn_input
turn_input=tkinter.Label(
master=self._dialog_window, text='Which color move first?',
font=Font)
turn_input.grid(
row=2, column=0, padx=10,pady=10, sticky=tkinter.W)
self._turn_entry = tkinter.Entry(
master = self._dialog_window, width = 20, font = Font)
self._turn_enter.grid(
row=2, column=1, padx=10,pady=10, sticky=tkinter.W)
#top_left_input
top_left_input=tkinter.Label(
master=self._dialog_window, text='Which color on top left?',
font=Font)
top_left_input.grid(
row=3, column=0, padx=10,pady=10, sticky=tkinter.W)
self._top_left_entry = tkinter.Entry(
master = self._dialog_window, width = 20, font = Font)
self._top_left_enter.grid(
row=3, column=1, padx=10,pady=10, sticky=tkinter.W)
#win_menthod_input
win_method_input=tkinter.Label(
master=self._dialog_window, text='win method?',
font=Font)
win_method_input.grid(
row=4, column=0, padx=10,pady=10, sticky=tkinter.W)
self._win_method_entry = tkinter.Entry(
master = self._dialog_window, width = 20, font = Font)
self._win_method_enter.grid(
row=4, column=1, padx=10,pady=10, sticky=tkinter.W)
button_frame = tkinter.Frame(master = self._dialog_window)
button_frame.grid(
row = 5, column = 0, columnspan = 2, padx = 10, pady = 10,
sticky = tkinter.E + tkinter.S)
ok_button = tkinter.Button(
master = button_frame, text = 'OK', font = Font,
command = self._on_ok_button)
ok_button.grid(row = 0, column = 0, padx = 10, pady = 10)
cancel_button = tkinter.Button(
master = button_frame, text = 'Cancel', font = Font,
command = self._on_cancel_button)
cancel_button.grid(row = 0, column = 1, padx = 10, pady = 10)
self._dialog_window.rowconfigure(5, weight = 1)
self._dialog_window.columnconfigure(1, weight = 1)
self._ok_clicked = False
self._column = ''
self._row = ''
self._turn=''
self._top_left=''
self._win_method=''
def show(self):
self._dialog_window.grab_set()
self._dialog_window.wait_window()
def was_ok_clicked(self) -> bool:
return self._ok_clicked
def get_column(self) -> str:
return self._column
def get_row(self) -> str:
return self._row
def get_turn(self)->str:
return self._turn
def get_top_left(self)->str:
return self._top_left
def get_win_method(self)->str:
return self._win_method
def _on_ok_button(self) -> None:
self._ok_clicked = True
self._column = self._column_entry.get()
self._row = self._row_entry.get()
self._turn = self._turn_entry.get()
self._top_left = self._top_left_entry.get()
self._win_menthod = self._win_method_entry.get()
self._dialog_window.destroy()
def _on_cancel_button(self) -> None:
self._dialog_window.destroy()
if __name__ == '__main__':
User_design().start()
答案 0 :(得分:0)
<?php
$id = $_GET['id'];
?>
因为你的法术错了。
答案 1 :(得分:0)
您的代码大约有5个部分引用enter
而不是entry
,因此您尝试设置的变量不存在。
使用enter
搜索并替换entry
,您应该很高兴。