简体   繁体   中英

Exception has occurred: TclError how do i fix it?

from tkinter import *
root = Tk()

upper = Frame(root)
upper.pack(side=TOP)
lower = Frame(root)
lower.pack(side=BOTTOM)

icon = Label(root, text='One', bg='red', fg='white')
icon.pack(upper, side=LEFT)
spacing = Label(root, bg='red')
spacing.pack(upper, side=RIGHT, fill=X)
fill = Label(root, text='Two', bg='green', fg='black')
fill.pack(lower, fill=BOTH, expand=True)

root.mainloop()

i try to do this code but it keeps coming up with:

Exception has occurred: TclError

bad option "-bd": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side

how do i fix this?

It appears you're trying to pack a widget inside another widget other than its parent. If that's the case, you must assign the frame to the in_ parameter.

icon.pack(in_=upper, side=LEFT)
spacing.pack(in_=upper,side=RIGHT, fill=X)
fill.pack(in_=lower, fill=BOTH, expand=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM