Tkinter Python,如何创建Y-xis滚动条?

时间:2018-10-18 21:14:12

标签: python tkinter

我正在尝试创建一个包含大量图像的tkinter窗口。但是,我无法创建沿y轴移动的滚动条。我已经尝试了多次,但是我太困惑了。 tkinter是否具有滚动条小部件?我已经标注了图像标签,因为您将没有这些图像。大量的代码请不要惊慌。大多数只是定义标签。 这是我的进口货。

Don't know why it seems that every time I copy past the code it doesn't indent properly.

堆栈溢出代码缩进系统无法让我正确缩进该代码。因此,这是一个pastebin链接: https://pastebin.com/Um8zv3Qr

import tkinter as tk
from tkinter import messagebox
from tkinter.font import Font
import mysql.connector
import random
import smtplib
import config
import string
def raise_frame(frame):
    frame.tkraise()
root=tk.Tk()
PatrolOverview=tk.Frame(root)
PatrolOverview.grid(row=0,column = 0, sticky= 'news')
SmallTextFont=Font(family="Arial",size="14")



#Badger Tkinter Variables
BadgerPL=tk.StringVar()
BadgerAPL=tk.StringVar()
BadgerScore=tk.IntVar()
    #Beaver Tkinter Variables
BeaverPL=tk.StringVar()
BeaverAPL=tk.StringVar()
BeaverScore=tk.IntVar()
    #Buffalo Tkinter Variables
BuffaloPL=tk.StringVar()
BuffaloAPL=tk.StringVar()
BuffaloScore=tk.IntVar()
    #Bull Tkinter Variables
BullPL=tk.StringVar()
BullAPL=tk.StringVar()
BullScore=tk.IntVar()
    #Bulldog Tkinter Variables
BulldogPL=tk.StringVar()
BulldogAPL=tk.StringVar()
BulldogScore=tk.IntVar()
    #Cobra Tkinter Variables
CobraPL=tk.StringVar()
CobraAPL=tk.StringVar()
CobraScore=tk.IntVar()





def PatrolOverviewRaiseFrame():
    AnimalNameList=["Badger","Beaver","Buffalo","Bull","Bulldog","Cobra"]
    for row in AnimalNameList:
        print(row)
        if row==("Badger"):
            #BadgerImageLabel = tk.Label(PatrolOverview, image=BadgerImage)
            #BadgerImageLabel.grid(row=3, column=1)
            BadgerNameLabel=tk.Label(PatrolOverview,text="Badger",font=SmallTextFont, bg="white")
            BadgerNameLabel.grid(row=3,column=2)
            BadgerPLLabel = tk.Label(PatrolOverview, textvariable=BadgerPL, font=SmallTextFont, bg="white")
            BadgerPLLabel.grid(row=3, column=3)
            BadgerAPLLabel = tk.Label(PatrolOverview, textvariable=BadgerAPL, font=SmallTextFont, bg="white")
            BadgerAPLLabel.grid(row=3, column=4)
            BadgerScoreBox= tk.Spinbox(PatrolOverview, textvariable=BadgerScore,from_=0,to_=500,font=SmallTextFont,bg="white")
            BadgerScoreBox.grid(row=3,column=5)
        if row==("Beaver"):
                #BeaverImageLabel = tk.Label(PatrolOverview, image=BeaverImage)
                #BeaverImageLabel.grid(row=4, column=1)
                BeaverNameLabel=tk.Label(PatrolOverview,text="Beaver",font=SmallTextFont, bg="white")
                BeaverNameLabel.grid(row=4,column=2)
                BeaverPLLabel = tk.Label(PatrolOverview, textvariable=BeaverPL, font=SmallTextFont, bg="white")
                BeaverPLLabel.grid(row=4, column=3)
                BeaverAPLLabel = tk.Label(PatrolOverview, textvariable=BeaverAPL, font=SmallTextFont, bg="white")
                BeaverAPLLabel.grid(row=4, column=4)
                BeaverScoreBox= tk.Spinbox(PatrolOverview, textvariable=BeaverScore,from_=0,to_=500,font=SmallTextFont,bg="white")
                BeaverScoreBox.grid(row=4,column=5)
        if row==("Buffalo"):
                #BuffaloImageLabel = tk.Label(PatrolOverview, image=BuffaloImage)
                #BuffaloImageLabel.grid(row=5, column=1)
                BuffaloNameLabel=tk.Label(PatrolOverview,text="Buffalo",font=SmallTextFont, bg="white")
                BuffaloNameLabel.grid(row=5,column=2)
                BuffaloPLLabel = tk.Label(PatrolOverview, textvariable=BuffaloPL, font=SmallTextFont, bg="white")
                BuffaloPLLabel.grid(row=5, column=3)
                BuffaloAPLLabel = tk.Label(PatrolOverview, textvariable=BuffaloAPL, font=SmallTextFont, bg="white")
                BuffaloAPLLabel.grid(row=5, column=4)
                BuffaloScoreBox= tk.Spinbox(PatrolOverview, textvariable=BuffaloScore,from_=0,to_=500,font=SmallTextFont,bg="white")
                BuffaloScoreBox.grid(row=5,column=5)
        if row==("Bull"):
                #BullImageLabel = tk.Label(PatrolOverview, image=BullImage)
                #BullImageLabel.grid(row=6, column=1)
                BullNameLabel=tk.Label(PatrolOverview,text="Bull",font=SmallTextFont, bg="white")
                BullNameLabel.grid(row=6,column=2)
                BullPLLabel = tk.Label(PatrolOverview, textvariable=BullPL, font=SmallTextFont, bg="white")
                BullPLLabel.grid(row=6, column=3)
                BullAPLLabel = tk.Label(PatrolOverview, textvariable=BullAPL, font=SmallTextFont, bg="white")
                BullAPLLabel.grid(row=6, column=4)
                BullScoreBox= tk.Spinbox(PatrolOverview, textvariable=BullScore,from_=0,to_=500,font=SmallTextFont,bg="white")
                BullScoreBox.grid(row=6,column=5)
        if row==("Bulldog"):
                #BulldogImageLabel = tk.Label(PatrolOverview, image=BulldogImage)
                #BulldogImageLabel.grid(row=7, column=1)
                BulldogNameLabel=tk.Label(PatrolOverview,text="Bulldog",font=SmallTextFont, bg="white")
                BulldogNameLabel.grid(row=7,column=2)
                BulldogPLLabel = tk.Label(PatrolOverview, textvariable=BulldogPL, font=SmallTextFont, bg="white")
                BulldogPLLabel.grid(row=7, column=3)
                BulldogAPLLabel = tk.Label(PatrolOverview, textvariable=BulldogAPL, font=SmallTextFont, bg="white")
                BulldogAPLLabel.grid(row=7, column=4)
                BulldogScoreBox= tk.Spinbox(PatrolOverview, textvariable=BulldogScore,from_=0,to_=500,font=SmallTextFont,bg="white")
                BulldogScoreBox.grid(row=7,column=5)
        if row==("Cobra"):
                #CobraImageLabel = tk.Label(PatrolOverview, image=CobraImage)
                #CobraImageLabel.grid(row=8, column=1)
                CobraNameLabel=tk.Label(PatrolOverview,text="Cobra",font=SmallTextFont, bg="white")
                CobraNameLabel.grid(row=8,column=2)
                CobraPLLabel = tk.Label(PatrolOverview, textvariable=CobraPL, font=SmallTextFont, bg="white")
                CobraPLLabel.grid(row=8, column=3)
                CobraAPLLabel = tk.Label(PatrolOverview, textvariable=CobraAPL, font=SmallTextFont, bg="white")
                CobraAPLLabel.grid(row=8, column=4)
                CobraScoreBox= tk.Spinbox(PatrolOverview, textvariable=CobraScore,from_=0,to_=500,font=SmallTextFont,bg="white")
                CobraScoreBox.grid(row=8,column=5)

raise_frame(PatrolOverview)
UnleashAnimals=tk.Button(root,text="UnleashAnimals",command=PatrolOverviewRaiseFrame)
UnleashAnimals.grid(row=1,column=1)
root.mainloop()

0 个答案:

没有答案