1

I am trying to convert a game I had previously written in command line into GUI (https://github.com/abhinavdhere/Share-Trader-PC/releases/tag/v1.0) I have built a menu like structure of buttons in one frame, and then on clicking help, the previous frame f1 should disappear and help text should be displayed. I used a Message widget to display the text but it is long and needs scrollbar. I tried to add a vertical scrollbar but couldn't make it work. I referred python and tkinter: using scrollbars on a canvas and tried to do it that way but it still displays only the Message but no scrollbar. Here is the function for it:

def help(self):
    self.f1.pack_forget()
    f2=tk.Frame(self,bg='#FFCC00')
    f2.grid(row=0,column=0)
    helpMan=open("Game Rules.txt","r")
    hText=helpMan.read()
    c1=tk.Canvas(f2,width=640,height=480,scrollregion=(0,0,700,500))
    c1.pack(side="left",expand=True,fill="both")
    text1=tk.Message(f2,text=hText)
    c1.create_window(0,0,anchor="nw",window=text1)
    scrollY=tk.Scrollbar(f2,orient="vertical",command=c1.yview)
    scrollY.pack(side="right",fill="y") 
    c1.config(yscrollcommand = scrollY.set)

P.S. Why is it such a hassle to make a simple scrollbar?

Community
  • 1
  • 1
Abhinav
  • 103
  • 2
  • 9
  • Please give us a [minimal, complete, verifiable example](http://stackoverflow.com/help/mcve). – abarnert Jun 05 '15 at 06:59
  • Meanwhile, when I embed this code in [the simplest program I could think of](http://pastebin.com/U2TEc1Yv) and run it, I get a vertical scrollbar displayed, and scrolling it does scroll the text up and down. – abarnert Jun 05 '15 at 07:03
  • Weird. I don't see any scrollbar, whereas your code looks same as mine. – Abhinav Jun 05 '15 at 11:22

1 Answers1

3

The message widget does not support scrolling. It is missing the commands yview and xview that are used for the scrolling protocol. It is really just a multiline label. It is also ugly and can't be themed.

You should replace the message widget with a text widget which also displays multiline text and can support scrolling and formatted text using tags to attach styling information if required.

To make the text widget look the same as the Message widget the following should work:

m = Message(root)
txt = Text(root, background=m.cget("background"), relief="flat",
    borderwidth=0, font=m.cget("font"), state="disabled")
m.destroy()
patthoyts
  • 32,320
  • 3
  • 62
  • 93