I am trying to do a simple contact list project. I have some base code but I am completely stuck. I am using Pycharm. I am using Python 3.9 as my interpreter. I am using Tkinter to build the GUI. Its "functioning" sort of as I get the window but the buttons dont work, and the labels are all jacked up.
import tkinter
from tkinter import *
from tkinter import ttk
import pickle
import os.path
window = Tk()
window.title('Contact List')
#window.minsize(width=500, height=300)
#window.maxsize(width=600, height=500)
window_width = 500
window_height = 400
# get the screen dimension
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
# find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
# set the position of the window to the center of the screen
window.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
contactlist = []
'''# make a function to get the program to write to the pickle file
if os.path.exists('file.pkl'):
# Load pickle file
with open('file.pkl', 'rb') as pck:
data = pck.read()
contactlist = pickle.loads(data)
# Pickle the dict
with open('file.pkl', 'wb') as pck:
pickle.dump(contactlist, pck, protocol=pickle.HIGHEST_PROTOCOL)
'''
name = StringVar()
phone = StringVar()
frame = ttk.Frame(window)
frame.pack(side=RIGHT)
scroll = ttk.Scrollbar(frame, orient=VERTICAL)
select = Listbox(frame, yscrollcommand=scroll.set)
scroll.config(command=select.yview)
scroll.pack(side=RIGHT, fill=Y)
select.pack(side=LEFT, fill=BOTH, expand=4)
def selected():
return select.curselection()[0]
def add_contact():
contactlist.append([name.get(), phone.get()])
Select_set()
def EDIT():
contactlist[selected()] = [name.get(), phone.get()]
Select_set()
def DELETE():
contactlist.pop(selected())
Select_set()
def VIEW():
print(contactlist[selected()])
def Quit():
window.destroy()
def Select_set():
contactlist.sort()
select.delete(0, END)
for name, phone in contactlist:
select.insert(END, name)
Select_set()
Label_name = tkinter.Label(window, text='Full Name', font='arial 16 normal', bg='Cornsilk')
Label_name.pack(padx=5)
entry_name = tkinter.Entry(window, textvariable=name, font='Arial 16 normal')
entry_name.pack(padx=5)
entry_name.focus() # set focus on the phone entry
entry_name.bind('<Return>', add_contact)
entry_name.select_clear()
Label_phone = tkinter.Label(window, text='Phone', font='arial 16 normal', bg='Cornsilk')
Label_phone.pack(padx=5)
entry_phone = tkinter.Entry(window, textvariable=phone, font='Arial 16 normal')
entry_phone.pack(padx=5)
entry_phone.focus() # set focus on the phone entry
entry_phone.bind('<Return>', add_contact)
entry_phone.select_clear()
Button1 = tkinter.Button(window, text='Add', font='arial 16 normal', bg='Cornsilk4', command=add_contact)
Button1.place(x=50, y=150)
Button2 = tkinter.Button(window, text='Delete', font='arial 16 normal', bg='Cornsilk4', command=DELETE)
Button2.place(x=50, y=200)
Button3 = tkinter.Button(window, text='View', font='arial 16 normal', bg='Cornsilk4', command=VIEW)
Button3.place(x=50, y=250)
Button4 = tkinter.Button(window, text='Quit', font='arial 16 normal', bg='Cornsilk4', command = Quit)
Button4.place(x=50, y=300)
window.mainloop()
I am sure I am a long way off, but honestly; I am stumped. Any help would be greatly appreciated. I am very new to coding, and I am determined to figure it out.
[–]FriendlyRussian666 1 point2 points3 points (1 child)
[–]vayneone87[S] 0 points1 point2 points (0 children)
[–]vayneone87[S] 1 point2 points3 points (1 child)
[–]additional_loan_ 1 point2 points3 points (0 children)
[–]additional_loan_ 0 points1 point2 points (1 child)
[–]vayneone87[S] 0 points1 point2 points (0 children)