如果我试图把信封放在一个拖车窗上,而该法典没有任何其他内容:
from tkinter import ttk
from tkinter import *
from tkinter.ttk import *
class Application(Frame):
def createWidgets(self):
self.can = Canvas(self.master, width=500, height=250)
self.can.grid(row=2, column=1)
self.can.create_line(0,0,500,200)
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
a 从未创造过窗户。 我发现,增加一个顿子,以创建信道:
from tkinter import ttk
from tkinter import *
from tkinter.ttk import *
class Application(Frame):
def makecanvas(self):
self.grid_forget()
self.can = Canvas(self.master, width=500, height=250)
self.can.grid(row=2, column=1)
self.can.create_line(0,0,500,200)
def createWidgets(self):
self.inst = Button(self)
self.inst["text"] = "GO!"
self.inst["command"] = self.makecanvas
self.inst.grid(row=3, column=1, pady=15, sticky=N)
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
Also, If I comment out the create canvas function, the button I removed with self.grid_forget() doesn t disappear. Is there a better way to do this?