user3808660
user3808660

Reputation:

Scroll bar messing up GUI size python

I have a text editor GUI with only a text area. I added a scrollbar and it re sizes the GUI to extremely small here is the top part of the script.

Keep in mind before I added the scrollbar the GUI was somewhat big which is what I wanted.

class Application(Frame):
def __init__(self, parent):
    Frame.__init__(self,parent)
    self.pack(side=LEFT,fill=BOTH,expand=YES)
    self.saved = None
    self.fontcolor = "Black"
    self.backgroundcolor = "White"
    self.fontsize = IntVar()
    self.check = None
    self.create_widgets()

def create_widgets(self):
    menubar = Menu(root)

    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="New", command=self.newfile)
    filemenu.add_command(label="Open", command=self.openfile)
    filemenu.add_command(label="Save", command=self.savefile)
    filemenu.add_command(label="Save As", command=self.saveas_file)
    menubar.add_cascade(label="File", menu=filemenu)

    formatmenu = Menu(menubar, tearoff=0)
    formatmenu.add_command(label="Font Size", command=self.fsc)
    formatmenu.add_command(label="Font Color", command=self.fcc)
    formatmenu.add_command(label="Background Color", command=self.bcc)
    menubar.add_cascade(label="Format", menu=formatmenu)

    helpmenu = Menu(menubar, tearoff=0)
    helpmenu.add_command(label="View help", command=self.helpfile)
    menubar.add_cascade(label="help", menu=helpmenu)

    root.config(menu=menubar)

    self.Cont = Text(self,wrap=WORD)
    self.Cont.pack(side=LEFT,fill=BOTH,expand=YES)

    self.Scroll = Scrollbar(self.Cont)
    self.Scroll.pack(side=RIGHT,fill=Y)
    self.Cont.configure(yscrollcommand=self.Scroll.set)

    root.protocol("WM_DELETE_WINDOW", self.verify)

Upvotes: 0

Views: 40

Answers (1)

furas
furas

Reputation: 142651

Scrollbar has wrong parent. It shouldn't be Text but Frame.

self.Scroll = Scrollbar(self)

BTW: You can set self.parent = parent in __init__ and then you can use self.parent in place of root. This way class doesn't depend on external variable.

Upvotes: 1

Related Questions