Python Forum
[Tkinter] Help with Scrollbar
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Help with Scrollbar
#1
Hi Folks, could someone help me with this code below please?
I just need to add a scrollbar to my result frame. I tried many ways but unfortunately without success.
Follow below my python code:

import os
from tkinter import *
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk, Image
from zeep import Client

HEIGHT = 600
WIDTH = 800

class BridgerSOAP:
    m_cliente = ""
    m_usuario = ""
    m_clave = ""
    m_cliente = None
    m_searchService = None
    m_contexto = None

    def __init__(self, cliente, usuario, clave):
        self.m_cliente = cliente
        self.m_usuario = usuario
        self.m_clave = clave
        # Get proxy default, port ACCESS
        self.m_cliente = Client('https://staging.bridger.lexisnexis.eu/LN.WebServices/11.2/XGServices.svc?wsdl',
                                service_name="XGServices")
        # Proxy for SEARCH port
        self.m_searchService = self.m_cliente.create_service(
            "{https://bridgerinsight.lexisnexis.com/BridgerInsight.Web.Services.Interfaces.11.2}BasicHttpBinding_ISearch",
            "https://staging.bridger.lexisnexis.eu/LN.WebServices/11.2/XGServices.svc/Search")
        # Proxy for port LISTMAINTENANCE
        self.m_ListMaintService = self.m_cliente.create_service(
            "{https://bridgerinsight.lexisnexis.com/BridgerInsight.Web.Services.Interfaces.11.2}BasicHttpBinding_IListMaintenance",
            "https://staging.bridger.lexisnexis.eu/LN.WebServices/11.2/XGServices.svc/ListMaintenance")

        contexto_tipo = self.m_cliente.get_type('ns1:ClientContext')
        self.m_contexto = contexto_tipo(ClientID=cliente, Password=clave, UserID=usuario)

        self.searchConfig_tipo = self.m_cliente.get_type("ns1:SearchConfiguration")
        self.searchInput_tipo = self.m_cliente.get_type("ns1:SearchInput")
        self.inputEntity_tipo = self.m_cliente.get_type("ns1:InputEntity")
        self.inputName_tipo = self.m_cliente.get_type("ns1:InputName")
        self.inputRecord_tipo = self.m_cliente.get_type("ns1:InputRecord")

    def search_individual(self, config, inputNames):
        inputRecords = []
        for name in inputNames:
            inputEntity = self.inputEntity_tipo(EntityType="Individual", Name=name)

            inputRecord = self.inputRecord_tipo(Entity=inputEntity)

            # You can setup many input record
            inputRecords.append(inputRecord)

        input = self.searchInput_tipo("?", {"InputRecord": inputRecords})
        return self.m_searchService.Search(self.m_contexto, config, input)

def show_entry_fields():

    firstname = first_name.get()
    lastname = last_name.get()
    middlename = ""

    # User and Password for Bridger Access
    bridger = BridgerSOAP("CLIENTID", "USERID", "PASS")

    # Predefined Search List configuration
    config = bridger.searchConfig_tipo(PredefinedSearchName="Lista de Busqueda", WriteResultsToDatabase=True)

    # Do the Search
    names = []
    names.append(bridger.inputName_tipo(First=firstname, Last=lastname, Middle=middlename))
    # print(names)
    resultado = bridger.search_individual(config, names)

    # RESULTS
    if resultado.Records == None:
        tk.Label(noresult_label,

                 text="No result found for this search.").grid(row=0,
                                                               column=0,
                                                               sticky=tk.W,
                                                               pady=4)
    else:
        for a in resultado.Records.ResultRecord:

            text = "=========== ALARM #{0} ===========\n" \
                   "Accept List: {1}  \n" \
                   "Alert State: {2}  \n" \
                   "Search Name: {3}  \n" \
                   "==============================\n".format(a.Record, a.RecordDetails.RecordState.AddedToAcceptList,
                                                             a.RecordDetails.RecordState.AlertState,
                                                             a.RecordDetails.Name.Full)
            numRec = 1
            for h in a.Watchlist.Matches.WLMatch:
                text += "\n" \
                        "Record #: {0}\n" \
                        "Auto False Positive: {1}\n" \
                        "Best Name: {2}\n" \
                        "Score: {3}\n" \
                        "False Positive: {4}\n" \
                        "File Name: {5}\n" \
                        "True Match: {6}\n" \
                        "Reason Listed: {7}\n".format(numRec, h.AutoFalsePositive, h.BestName, h.BestNameScore,
                                                      h.FalsePositive,
                                                      h.File.Name, h.TrueMatch, h.ReasonListed)
                numRec += 1

            numRec -= 1
            text += "\n" \
                    "Total # Record(s): {0}".format(numRec)

            tk.Label(result_label, background='#FFFFFF', text=text, font='Calibri 16').grid(row=0,
                                                                                      column=0,
                                                                                      sticky=tk.E,
                                                                                      pady=1, padx=1)


#def clear_fields():
#    first_name.delete(first=0, last=30)
#    last_name.delete(first=0, last=30)

def restart_program():
    python = sys.executable
    os.execl(python, python, *sys.argv)


root = tk.Tk()
root.title("Bridger Search")
root.config(bg='#ffffff')

labelframe = LabelFrame(root, text="Name Screening")
labelframe.pack(fill="both", expand="yes")

canvas = tk.Canvas(labelframe, height=HEIGHT, width=WIDTH)
canvas.pack()

frame = tk.Frame(root, bg='#ff0000', bd=3)
frame.place(relx=0.5, rely=0.12, relwidth=0.25, relheight=0.1, anchor='n')

first_name = tk.Entry(frame)
first_name.place(relwidth=0.65, relheight=0.5, relx=0.01)

last_name = tk.Entry(frame)
last_name.place(relwidth=0.65, relheight=0.5, relx=0.01, rely=0.5)

firstname_text = Label(labelframe, text="First Name:")
firstname_text.place(relx=0.290, rely=0.127)

lastname_text = Label(labelframe, text="Last Name:")
lastname_text.place(relx=0.290, rely=0.177)

result_text = Label(labelframe, text="Result:")
result_text.place(relx=0.2, rely=0.20, relwidth=0.1, relheight=0.1, anchor='n')

search_text = Label(labelframe, text="Search Fields:")
search_text.place(relx=0.46, rely=0.07, relwidth=0.2, relheight=0.04, anchor='n')

api_text = Label(labelframe, text="Bridger XG 5 API for Web Services Demo Only. Developed by Jacques Jacob")
api_text.place(relx=0.50, rely=0.965, anchor='n')

button = tk.Button(frame, text="Search", command=lambda: show_entry_fields())
button.place(relx=0.99, rely=0.5, relheight=0.5, relwidth=0.31, anchor='ne')

button_clear = tk.Button(frame, text='Reset', command=lambda: restart_program())
button_clear.place(relx=0.99, rely=0.00, relheight=0.5, relwidth=0.31, anchor='ne')

button_quit = tk.Button(root, text='Quit', command=root.quit)
button_quit.place(relx=0.83, rely=0.12, relheight=0.04, relwidth=0.1, anchor='ne')

lower_frame = tk.Frame(root, bg='#ff0000', bd=10)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.7, relheight=0.6, anchor='n')

path = "image.png"
load = Image.open(path)
load = load.resize((160, 80), Image.ANTIALIAS)
render = ImageTk.PhotoImage(load)

panel = tk.Label(root, image=render)
panel.pack(side="bottom", fill="both", expand="yes")

label = tk.Label(lower_frame)
label.place(relwidth=1, relheight=1)

noresult_label = tk.Label(label)
noresult_label.place(relx=0.33)

result_label = tk.Label(label)
result_label.place(relx=0.1, relheight=0.99)

root.resizable(False, False)

root.mainloop()
Reply
#2
Quote:add a scrollbar to my result frame
what is the name of your 'result frame'?
Reply
#3
(Mar-09-2020, 10:35 PM)Larz60+ Wrote:
Quote:add a scrollbar to my result frame
what is the name of your 'result frame'?

result_label
Reply
#4
That's a Label, not a Frame.
Quote:The Scrollbar widget is almost always used in conjunction with a Listbox, Canvas, or Text widget. Horizontal scrollbars can also be used with the Entry widget.
source: http://effbot.org/tkinterbook/scrollbar.htm

Labels should only be used as labels or to display simple text, they actually do have a relatively rich attribute set for what they were intended for, so will work in a lot of situations, but better to stick to original intent, to make your code clearer.

I don't think scrollbars will work here, but here's an example with frame widget I wrote several years ago: https://python-forum.io/Thread-Show-Inst...ht=tkinter

By the way, you can get a tkinter manual here: reu.cct.lsu.edu/documents/Python_Course/tkinter.pdf
This was written some time ago, but still the bible of tkinter, and almost none of it has changed.
Get it here
Reply
#5
(Mar-09-2020, 10:54 PM)Larz60+ Wrote: That's a Label, not a Frame.
Quote:The Scrollbar widget is almost always used in conjunction with a Listbox, Canvas, or Text widget. Horizontal scrollbars can also be used with the Entry widget.
source: http://effbot.org/tkinterbook/scrollbar.htm

Labels should only be used as labels or to display simple text, they actually do have a relatively rich attribute set for what they were intended for, so will work in a lot of situations, but better to stick to original intent, to make your code clearer.

I don't think scrollbars will work here, but here's an example with frame widget I wrote several years ago: https://python-forum.io/Thread-Show-Inst...ht=tkinter

By the way, you can get a tkinter manual here: reu.cct.lsu.edu/documents/Python_Course/tkinter.pdf
This was written some time ago, but still the bible of tkinter, and almost none of it has changed.
Get it here

Thanks!!
I'm trying but I don't know why isn't possible to create the scrollbar... I changed to Canvas or ListBox but still not working... Wall
Reply
#6
It is working now. Thanks folks!!! Wink
Reply
#7
Please let us know what worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,432 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  [Tkinter] Scrollbar apffal 7 3,057 Oct-11-2021, 08:26 PM
Last Post: deanhystad
Question [Tkinter] How to configure scrollbar dimension? water 6 3,373 Jan-03-2021, 06:16 PM
Last Post: deanhystad
  [PyQt] scrollbar in tab issac_n 1 3,542 Aug-04-2020, 01:33 PM
Last Post: deanhystad
  [Tkinter] Scrollbar in tkinter PatrickNoir 2 3,262 Jul-26-2020, 06:02 PM
Last Post: deanhystad
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 9,302 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  [Tkinter] Same Scrollbar for two text area smabubakkar 3 2,807 Jun-19-2019, 05:26 PM
Last Post: Denni
  Scrollbar rturus 5 14,961 Jun-06-2019, 01:04 PM
Last Post: heiner55
  [PyGUI] Create a scrollbar in GUI to add test cases mamta_parida 1 3,583 Sep-27-2018, 11:57 AM
Last Post: Larz60+
  [Tkinter] Scrollbar problem & general organization weatherman 13 13,320 Apr-16-2017, 12:55 PM
Last Post: weatherman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020