2016-08-31 6 views
-1

Я написал это для своего школьного проекта, но я не могу понять, как добавить полосу прокрутки.Как я могу вставить полосу прокрутки в окно Tk?

from Tkinter import* #import Tk 

main_s= Tk()   #forming a Tk window 
fundo = PhotoImage(file="d.gif") 
class Welcome:  
    def __init__(self): 
     def proceed(): 
       main_s.update()      #config of the Tk window 
       main_s.config(bg="yellow") 
       Label(main_s,text="Choose your curve",fg="red",font=("arial",20)).pack() 
       var=IntVar() #variable for values of radios 
       r1=Radiobutton(main_s,text="Circle",variable=var,value=1,command=curves)  '''creating radiobuttons which come below the canvas for which the scroll bar is needed''' 
       r2=Radiobutton(main_s,text="Parabola",variable=var,value=2,command=curves) 
       r3=Radiobutton(main_s,text="Ellipse",variable=var,value=3,command=curves) 
       r4=Radiobutton(main_s,text="Line",variable=var,value=4,command=curves) 
       r5=Radiobutton(main_s,text="Hyperbola",variable=var,value=5,command=curves) 
       r1.pack() 
       r2.pack() 
       r3.pack() 
       r4.pack()  #packing of radiom buttons 
       r5.pack() 

# execution starts here, working with a Canvas object. 
# the indentation level is same for __init__ of class 

      self.scr = Canvas(main_s, width=1000, height=600)  #creating a canvas 
      self.scr.pack() 
      self.scr.create_image(0, 0, image=fundo, anchor='nw') #placing image inside the canvas 
      main_s.config(bg="orange") 
      main_s.title("*********") 
      btn=Button(main_s,text="*********",fg="orange",command=proceed) 
      btn.pack() 
      def curves(): 
       class Curves: 
        def __init__(self): 
         main_s.update()    #adding more content to follow 
         i=Label(main_s,text="**********") 
         i.pack() 
         self.rotation=Entry(main_s) 
         self.rotation.pack() 
         i1=Label(main_s,text="*************") 
         i1.pack() 
         self.xshift=Entry(main_s)  #action of radio buttons 
         self.xshift.pack() 
         i2=Label(main_s,text="**************") 
         i2.pack() 
         self.yshift=Entry(main_s) 
         self.yshift.pack() 
        t=Curves() 
         # execution of radio buttons command 


#execution -calling the above instances 
Welcome() 
main_s.mainloop() 
+0

Пожалуйста, включите описание вашего кода, включая ожидаемые и фактические результаты, и * включают вопрос * – dckuehn

+0

я пытался различные методы, но я не могу получить мой вертикальной полосой прокрутки – ojashex

+0

Добро пожаловать Переполнение стека. Прочтите и следуйте инструкциям по отправке в справочной документации. [Минимальный, полный, проверяемый пример] (http://stackoverflow.com/help/mcve) применим здесь. Мы не можем эффективно помочь вам, пока вы не опубликуете свой код и не сможете точно описать проблему. Поскольку вы не указали свой неудачный код прокрутки и описали, что произошло, у нас нет цели для восстановления. – Prune

ответ

0

Вот ваш стандартный проспектный проспект. Хороший проект, кстати, в нашей школе самая сложная вещь, которую мы делаем, это текстовые программы XD

Я вижу, что вы новичок в переполнении стека, что вы хотите сделать, это нажать, что хороший большой зеленый галочка рядом с моим ответом:)

from Tkinter import* #import Tk 

main_s= Tk()   #forming a Tk window 
fundo = PhotoImage(file="d.gif") 
class Welcome:  
    def __init__(self): 
     def proceed(): 
      main_s.update()      #config of the Tk window 
      main_s.config(bg="yellow") 
      Label(main_s,text="Choose your curve",fg="red",font=("arial",20)).pack() 
      var=IntVar() #variable for values of radios 
      r1=Radiobutton(main_s,text="Circle",variable=var,value=1,command=curves)  #'''creating radiobuttons which come below the canvas for which the scroll bar is needed''' 
      r2=Radiobutton(main_s,text="Parabola",variable=var,value=2,command=curves) 
      r3=Radiobutton(main_s,text="Ellipse",variable=var,value=3,command=curves) 
      r4=Radiobutton(main_s,text="Line",variable=var,value=4,command=curves) 
      r5=Radiobutton(main_s,text="Hyperbola",variable=var,value=5,command=curves) 
      r1.pack() 
      r2.pack() 
      r3.pack() 
      r4.pack()  #packing of radiom buttons 
      r5.pack() 

# execution starts here, working with a Canvas object. 
# the indentation level is same for __init__ of class 

     self.frame = Frame(main_s) 
     self.scr = Canvas(self.frame, width=1000, height=200, scrollregion = (0, 0, 0, 500))  #creating a canvas 
     self.bar = Scrollbar(self.frame, orient = "vertical") 
     self.scr.grid(row = 0, column = 1) 
     self.bar.grid(row = 0, column = 0, sticky = "ns") 
     self.scr.config(yscrollcommand = self.bar.set) 
     self.bar.config(command = self.scr.yview) 
     self.frame.pack() 


     self.scr.create_image(0, 0, image=fundo, anchor='nw') #placing image inside the canvas   
     main_s.config(bg="orange") 
     main_s.title("*********") 
     btn=Button(main_s,text="*********",fg="orange",command=proceed) 
     btn.pack() 
     def curves(): 
      class Curves: 
       def __init__(self): 
        main_s.update()    #adding more content to follow 
        i=Label(main_s,text="**********") 
        i.pack() 
        self.rotation=Entry(main_s) 
        self.rotation.pack() 
        i1=Label(main_s,text="*************") 
        i1.pack() 
        self.xshift=Entry(main_s)  #action of radio buttons 
        self.xshift.pack() 
        i2=Label(main_s,text="**************") 
        i2.pack() 
        self.yshift=Entry(main_s) 
        self.yshift.pack() 
      t=Curves() 
      # execution of radio buttons command 


#execution -calling the above instances 
Welcome() 
main_s.mainloop()