私は、Windowsのサイズを変更させるためにcolumnconfigureまたはrowconfigureメソッドを使用しようとしたところにコメントがありますが、動作していないようです。私もmainloop()を取り出すことができ、私のプログラムはまったく同じように動作します。これは私がおそらく/ mainloopを正しく使用しているとは信じられません。メソッドは主に組織化のためのものであり、今は再利用可能なメソッドではないことがわかっています。私はたぶんそれをいくつかの点で修正する予定だったが、それはこの記事の目的ではない。ウィンドウのサイズを変更すると、これらのttkアプリケーションのサイズを強制的に変更するにはどうすればよいですか?
#!/usr/bin/python
from tkinter import *
from tkinter import ttk
import webbrowser
from dictionary import *
class AI():
def __init__(self):
self.urls = dictionary.get()
self.makeMainframe()
self.makeLabels()
self.makeDropDown()
self.makeButton()
self.makeEntry()
for child in self.mainframe.winfo_children():
child.grid_configure(padx=2, pady=2)
#child.columnconfigure(index='all',weight=1)
#child.rowconfigure(index='all',weight=1)
def openMenu(self):
webbrowser.open(self.urls[self.lunchVar.get()])
print(self.urls[self.lunchVar.get()])
def saveChoice(self, event):
print(self.foodVar.get())
def makeMainframe(self):
self.mainframe = ttk.Frame(padding="3 3 12 12")
self.mainframe.grid(column=0, row=0, sticky=(N,W,E,S))
#self.mainframe.columnconfigure('all', weight=1)
#self.mainframe.rowconfigure(index='all', weight=1)
def makeDropDown(self):
self.lunchVar = StringVar()
self.lunchChoice = ttk.Combobox(self.mainframe, textvariable=self.lunchVar, state='readonly')
self.lunchChoice['values'] = list(self.urls.keys())
self.lunchChoice.grid(column=2, row=1, sticky=(W, E))
def makeLabels(self):
ttk.Label(self.mainframe, text="Today's lunch is from...").grid(column=1, row=1, sticky=(E,W))
ttk.Label(self.mainframe, text="Click here for a menu -->").grid(column=1, row=2, sticky=(E,W))
ttk.Label(self.mainframe, text="What will you be having?").grid(column=1, row=3, sticky=(E,W))
def makeButton(self):
self.menu = ttk.Button(self.mainframe, textvariable=self.lunchVar, command=self.openMenu)
self.menu.grid(column=2, row=2, sticky=(W, E))
def makeEntry(self):
self.foodVar = StringVar()
self.foodChoice = ttk.Entry(self.mainframe, textvariable=self.foodVar)
self.foodChoice.grid(column=2, row=3, sticky=(E,W))
self.foodChoice.bind("<Return>", self.saveChoice)
#self.foodChoice.columnconfigure(index='all', weight=1)
AI=AI()
mainloop()
インデントの一部が壊れています –