Tags » Tkinter

Python Code Snippets #18

Python Newb Code Snippets #18

86-Get Video File Info

This heavily Shambleized snippet could easily be used as a function inside any code that deals with videos files. 1,599 more words

Code Snippets

Tkinter TreeView - Enable Sorting upon Clicking Column Headings

The below code snippet can help you achieve the Sorting Option on Treeview Column Headings in Tkinter in both ascending and descending order.

columns = ("Student","Course","Last Session")

tv = Treeview(popup, show='headings', columns=columns,height=25)

def treeview_sort_column(tv, col, reverse):
    l = [(tv.set(k, col), k) for k in tv.get_children('')]
    l.sort(reverse=reverse)

    # rearrange items in sorted positions
    for index, (val, k) in enumerate(l):
        tv.move(k, '', index)

    # reverse sort next time
    tv.heading(col, command=lambda _col=col: treeview_sort_column(tv, _col, not reverse))

for col in columns:
    tv.heading(col, text=col,command=lambda _col=col: treeview_sort_column(tv, _col, False))
tv.pack()

 

ModuleNotFoundError: No module named 'babel.numbers'

Traceback (most recent call last):
File "tkinter/__init__.py", line 1705, in __call__
File "script.py", line 726, in
File "script.py", line 536, in calendar
File "tkcalendar/calendar_.py", line 211, in __init__…
90 more words

Get Pyinstaller to import ttkthemes

Operating System: Mac OS

The below solution worked perfectly

Step 1
pyinstaller script_name.py --hidden-import ttkthemes

Step 2
Copy the ttkthemes folder from venv/lib/python3.x/site-packages folder in your distribution folder (dist)

Tkinter Entry insert: " 'Nonetype' object has no attribute 'insert'

The .pack or .grid method of a widget always returns None. So ensure the the .path or .grid method of the Entry Widget is always on a separate line. 7 more words

Desktop database program -- part 2 : the backend

There’s not much to say here.
Second part of the post.
In this Part I will show you the backend script of the program.

"""


//***********************************************************************
//***********************************************************************
//**********            CODE BY : VIRTUAL SODA            ***************
//***********************************************************************
//***********************************************************************


//***********************************************************************
//***********************************************************************
//**********                    WARNING                   ***************
//***********************************************************************
//***********************************************************************
//**********         USE THIS CODE AT YOUR OWN RISK     *****************
//***********************************************************************
//**                                                                  ***
//**       THIS SOURCE FILE CAN BE COMPILED AND IT WILL RUN           ***
//***********************************************************************



 ************************************************************************
 
 DOWNLOAD EXE LINK:  
 
    https://www.mediafire.com/file/oh1vztpw3qzve5l/desktop_database.rar/file
 
 
 INSTRUCTIONS : ONCE YOU DOWNLOADED THE .ZIP , UNZIP IT,OPEN THE FOLDER,
                AND YOU WILL SEE TWO FOLDERS, ONE WITH THE PROJECT FILES
                AND OTHER WITH THE EXE FILE
 
 
 ***********************************************************************
 

  
    
"""











# IMPORT SECTION    
#-----------------------------------------------------

import sqlite3
    
#-----------------------------------------------------




# create and connect to the database   
#-----------------------------------------------------
def connect():


    db_connection = sqlite3.connect("books_database.db")


    cursor = db_connection.cursor()

    
    # NOTE : THE EXECUTE COMMAND (ALL THE FUNCTION PARAMETERS)
    # MUST BE IN 1 LINE , OTHERWISE THE PROGRAM WILL NOT RUN 
    # I PUT IT IN THIS WAY TO MAKE IT MORE READABLE 
    
    cursor.execute("CREATE TABLE IF NOT EXISTS 
                    books(id INTEGER PRIMARY KEY, title TEXT,author TEXT, year INTEGER, isbn INTEGER)")
    

    db_connection.commit()


    db_connection.close()




  



# insert_record 
#-----------------------------------------------------

def insert_record(title, author, year, isbn):


    db_connection = sqlite3.connect("books_database.db")
    
    cursor = db_connection.cursor()
    
    cursor.execute("INSERT INTO books VALUES(NULL,?,?,?,?)",(title, author, year, isbn))

    
    db_connection.commit()
    
    db_connection.close()
    
    
    


    
# delete_record
#-----------------------------------------------------

def delete_record(id):


    db_connection = sqlite3.connect("books_database.db")
    
    cursor = db_connection.cursor()
    
    cursor.execute("DELETE FROM books WHERE id = ?",(id,))

    db_connection.commit()
    
    db_connection.close()
    
    
    

    
    
# update_record 
#-----------------------------------------------------

def update_record(id, title, author, year, isbn):


    db_connection = sqlite3.connect("books_database.db")
    
    cursor = db_connection.cursor()
    
    cursor.execute("UPDATE books SET title = ?, author = ?, year = ?, isbn = ? 113 more words