Python Forum
[Tkinter] how do i add a margin to a Listbox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] how do i add a margin to a Listbox
#18
Here is the window_2 portion of the code. I have removed a few lines regarding the image used for the background and the binding for clicking the items from the query to load the actual recipe (line 94). I have also changed the code to remove the pack() and I have only used place() as you have pointed out.

import os
import tkinter
import sqlite3
import win32print
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
#===================================== MAIN ====================================
def main():
#============================= CONNECT TO DATABASE =============================
    conn = sqlite3.connect('Recipe.db')
    c = conn.cursor()
#========================= CREATE DATABASE WITH TABLES =========================
    c.execute('''CREATE TABLE IF NOT EXISTS Recipes(
    Dish_Type CHAR(50),
    Recipe CHAR(50),
    Cook_Time CHAR(15),
    Serves CHAR(8),
    Ingredients CHAR(10000) ,
    Instructions CHAR(10000));''')
    conn.commit()

    c.execute('''CREATE TABLE IF NOT EXISTS Version(
    Welcome Decimal(10));''')
    conn.commit()

    c.execute('''CREATE TABLE IF NOT EXISTS Welcome(
    Welcome TEXT(2500));''')
    conn.commit()
#================================== WINDOW 2 ===================================
    window_2 = tkinter.Tk()
    window_2.title('Recipes')
    w = 1024
    h = 612
    ws = window_2.winfo_screenwidth()
    hs = window_2.winfo_screenheight()
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    window_2.geometry('%dx%d+%d+%d' % (w, h, x, y))
#================================ SELECT QUERY =================================
    def select():
        try:
            output.delete(0, END)
            selection = var.get()
            c.execute('SELECT Recipe FROM Recipes WHERE Dish_Type = :selection ORDER BY Recipe DESC',
            {'selection': selection})
            results = c.fetchall()
            for recipe, in results:
                output.insert(0,recipe)
        except:
            messagebox.showerror('Recipes', 'Failed to load category')
#================================ OPTION MENU ==================================
    var = tkinter.StringVar(window_2)
    var.set('Category')
    choices = [
        'Appetizers',
        'Beef',
        'Beverages',
        'Bakery',
        'Desserts',
        'Eggs',
        'Lamb',
        'Pasta',
        'Pork',
        'Potato',
        'Poultry',
        'Rice',
        'Salads',
        'Sandwiches',
        'Sauces/Dips',
        'Sea Food',
        'Slow Cooker',
        'Soups/Chili',
        'Stews',
        'Sushi',
        'Vegetables',
        'Vegetarian',
        'Wild Game']
    option = tkinter.OptionMenu(window_2, var, *choices)
    option.config(font=('Times 9 bold'), bg = '#F9F8D6', fg = '#9A0615')
    option.place(x=210, y=136)
    option['menu'].config(bg = '#F9F8D6', fg = '#9A0615')
    button = tkinter.Button(window_2, text='Load Category',
    font=('Times 9 bold'), bg = '#F9F8D6', fg = '#9A0615', command=select)
    button.place(x=362, y=139)
#=================================== WINDGETS ==================================
    output = tkinter.Listbox(window_2, font=('Times 10'), height = 20,
    width=42, bd=0, bg = '#FFD599', fg = '#9A0615', selectmode=SINGLE)
    output.place(x=210, y=195)
    yscroll1 = tkinter.Scrollbar(command=output.yview,
    orient=tkinter.VERTICAL)
    yscroll1.place(x=463, y=196)
    output.configure(yscrollcommand=yscroll1.set)
##    output.bind('<ButtonRelease-1>', getRecipe)
    window_2.mainloop()
if __name__ == '__main__':
    main()
"Often stumped... But never defeated."
Reply


Messages In This Thread
how do i add a margin to a Listbox - by DT2000 - Mar-31-2019, 06:04 PM
RE: how do i add a margin to a Listbox - by Larz60+ - Mar-31-2019, 08:14 PM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-01-2019, 07:14 AM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-01-2019, 08:44 AM
RE: how do i add a margin to a Listbox - by wuf - Apr-01-2019, 10:01 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-01-2019, 08:26 PM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-01-2019, 09:44 PM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-01-2019, 11:06 PM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-02-2019, 02:13 AM
RE: how do i add a margin to a Listbox - by wuf - Apr-02-2019, 11:46 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-02-2019, 07:30 PM
RE: how do i add a margin to a Listbox - by wuf - Apr-02-2019, 08:45 PM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-03-2019, 12:08 AM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-03-2019, 01:00 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-03-2019, 01:27 AM
RE: how do i add a margin to a Listbox - by wuf - Apr-03-2019, 05:53 AM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-03-2019, 02:35 PM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-04-2019, 11:56 PM
RE: how do i add a margin to a Listbox - by wuf - Apr-05-2019, 08:29 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-05-2019, 10:18 PM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-08-2019, 01:09 AM
RE: how do i add a margin to a Listbox - by wuf - Apr-08-2019, 06:51 AM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-08-2019, 08:05 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-09-2019, 05:18 AM
RE: how do i add a margin to a Listbox - by wuf - Apr-09-2019, 09:54 AM
RE: how do i add a margin to a Listbox - by DT2000 - Apr-09-2019, 08:25 PM
RE: how do i add a margin to a Listbox - by Larz60+ - Apr-09-2019, 08:49 PM
RE: how do i add a margin to a Listbox - by DT2000 - May-14-2019, 04:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Text Button - How Do I Reduce The Margin? vman44 6 11,309 Apr-27-2020, 10:48 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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