を編集私のコードです:Tkinterの動的なウィジェットここ
class render_window:
def __init__(self, height, width, window_title):
self.root_window = Tk()
w = width
h = height
ws = self.root_window.winfo_screenwidth() # width of the screen
hs = self.root_window.winfo_screenheight() # height of the screen
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
self.root_window.title(window_title)
self.root_window.minsize(width, height)
self.root_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
def new_button(self, button_text, button_command="", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
self.button = ttk.Button(self.root_window, text=button_text, command=button_command)
self.button.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
self.responsive_grid(grid_row, grid_column)
def new_label(self, label_text, text_alignment="center", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
self.label = ttk.Label(self.root_window, text=label_text, anchor=text_alignment)
self.label.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
self.responsive_grid(grid_row, grid_column)
def new_progress_bar(self, pg_length=250, pg_mode="determinate", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
self.progress_bar = ttk.Progressbar(self.root_window, length=pg_length, mode=pg_mode)
self.progress_bar.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
self.responsive_grid(grid_row, grid_column)
def responsive_grid(self, row_responsive=0, column_responsive=0, row_weight_num=1, column_weight_num=1):
self.root_window.grid_columnconfigure(column_responsive, weight=column_weight_num)
self.root_window.grid_rowconfigure(row_responsive, weight=row_weight_num)
options_window = render_window(200, 250, "Options Window")
options_window.new_progress_bar()
options_window.progress_bar.start()
options_window.new_progress_bar(grid_column=1)
options_window.progress_bar.start()
options_window.new_label("Options Window\And other buttons...", grid_row=1, grid_columnspan=2)
options_window.root_window.mainloop()
私はTkinterのを使用して比較的容易にインタフェースの作成を可能にするシステムを作成しました。私はすでに存在する要素を変更することに問題があります。複数のインスタンスを作成した場合、変更することはできません。作成された最後の要素のみを編集できます。私が修正/編集を言うとき、私は.config()について話しています。
私が行うたびに: options_window.progress_bar.config(args_here)は、作成された最後のバーについてのみ行います。コードを実行できるバーを指定する方法はありますか?
ありがとうございます!
リストまたは辞書を使用して各ウィジェットの参照を保持する –
@BryanOakley、どうすればよいですか? –