我为我的学校项目写了这篇文章,但我无法弄清楚如何添加滚动条。
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 :(得分: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()