Mar-02-2019, 01:10 PM
Please, how can I wrap and unwrap the 'wrap' attribute of the Text Widget by toggle with the check button (Word Wrap) in the sub-menu of my Menu Widget. Once it's checked the xscrolledbar (horizontal) should hide with the attribute 'wrap' set to WORD and once unchecked the xscrolledbar should show/display with wrap attribute set to NONE.
Thanks.
Thanks.
from tkinter import * from tkinter import ttk import Pmw class Notepad: def __init__(self): self.master = Tk() self.master.title("Untitled - Notepad") self.master.geometry('600x450+361+150') self.build_Notepad() self.master.mainloop() def build_Notepad(self): # BUILD FILE MENU self.frame = ttk.Frame(self.master) self.frame.pack() self.menu = Menu(self.frame,takefocus=1) self.master.configure(menu=self.menu) self.filemenu = Menu(self.menu,tearoff=False) # FORMAT MENU self.menu.add_cascade(label='Format',menu=self.filemenu) for i in ('Word Wrap','Font...'): self.wrap = BooleanVar() self.wrap.set(1) if i == 'Word Wrap': self.filemenu.add_checkbutton(label=i,offvalue=0,variable=self.wrap,command=self.wrap_text) else: self.filemenu.add_command(label=i) #BUILD TEXT AREA AND SCROLLED BAR self.frame_2 = ttk.Frame(self.master) self.frame_2.pack(fill=BOTH, expand=True) self.scrollbar = ttk.Scrollbar(self.frame_2) self.scrollbar.pack(side=RIGHT, fill=Y, expand=False) self.scrollbar_2 = ttk.Scrollbar(self.master, orient=HORIZONTAL) self.scrollbar_2.pack(fill=X, expand=NO) self.text = Text(self.frame_2,yscrollcommand=self.scrollbar.set,xscrollcommand=self.scrollbar_2.set,wrap=NONE) self.text.pack(side=LEFT,fill=BOTH,expand=True) self.scrollbar.configure(command=self.text.yview) self.scrollbar_2.configure(command=self.text.xview) def display_xview(self): self.scrollbar_2 = Scrollbar(self.master,command=self.text.xview,orient=HORIZONTAL) self.scrollbar_2.pack(fill=X,expand=NO) self.text.config(xscrollcommand=self.scrollbar_2.set) def wrap_text(self): self.use = self.wrap.get() if self.use: self.text.config(wrap=NONE) else: self.text.config(wrap=WORD) if __name__== "__main__": Notepad()