Table width expands when adding rows. #51
Unanswered
pythoncodingnewbie
asked this question in
Q&A
Replies: 5 comments 1 reply
-
@pythoncodingnewbie Show any example code/image. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have included the before and after images, and below is the code of my
function.
#Creating functionality for adding employees to list.
def employee_add():
addbox = ctk.CTkToplevel(root)
addbox.title("Employee Data")
addbox.geometry("360x575")
addbox.focus()
addbox.grab_set()
#Creates functionality for cancel button.
def cancel():
addbox.destroy() #Closes addbox toplevel.
def addbutton():
#The addbutton function takes values from the input boxes and
adds this to the table as a new row.
employeevalues = [fnentry.get(), lnentry.get(), a1entry.get(),
a2entry.get(), centry.get(), sentry.get(), zentry.get(), socentry.get(),
wentry.get(), salentry.get()]
table.add_row(values=employeevalues)
addbox.destroy()
#home()
#employee()
#This is the portion for creating the labels, input boxes, and
buttons in the addbox.
label = ctk.CTkLabel(master=addbox, text="First Name:")
label.grid(row=0, column=0, padx=20, pady=10, sticky="ew")
fnentry = ctk.CTkEntry(master=addbox, placeholder_text='John')
fnentry.grid(row=0, column=1, columnspan=3, padx=20, pady=10, sticky
="ew")
label = ctk.CTkLabel(master=addbox, text="Last Name:")
label.grid(row=1, column=0, padx=20, pady=10, sticky="ew")
lnentry = ctk.CTkEntry(master=addbox, placeholder_text='Smith')
lnentry.grid(row=1, column=1, columnspan=3, padx=20, pady=10, sticky
="ew")
label = ctk.CTkLabel(master=addbox, text="Address 1:")
label.grid(row=2, column=0, padx=20, pady=10, sticky="ew")
a1entry = ctk.CTkEntry(master=addbox, placeholder_text='123 Road St'
)
a1entry.grid(row=2, column=1, columnspan=3, padx=20, pady=10, sticky
="ew")
label = ctk.CTkLabel(master=addbox, text="Address 2:")
label.grid(row=3, column=0, padx=20, pady=10, sticky="ew")
a2entry = ctk.CTkEntry(master=addbox, placeholder_text='321 Street
Dr')
a2entry.grid(row=3, column=1, columnspan=3, padx=20, pady=10, sticky
="ew")
label = ctk.CTkLabel(master=addbox, text="City:")
label.grid(row=4, column=0, padx=20, pady=10, sticky="ew")
centry = ctk.CTkEntry(master=addbox, placeholder_text='Faketown')
centry.grid(row=4, column=1, columnspan=3, padx=20, pady=10, sticky=
"ew")
label = ctk.CTkLabel(master=addbox, text="State:")
label.grid(row=5, column=0, padx=20, pady=10, sticky="ew")
sentry = ctk.CTkEntry(master=addbox, placeholder_text='Florida')
sentry.grid(row=5, column=1, columnspan=3, padx=20, pady=10, sticky=
"ew")
label = ctk.CTkLabel(master=addbox, text="Zip Code:")
label.grid(row=6, column=0, padx=20, pady=10, sticky="ew")
zentry = ctk.CTkEntry(master=addbox, placeholder_text='90210')
zentry.grid(row=6, column=1, columnspan=3, padx=20, pady=10, sticky=
"ew")
label = ctk.CTkLabel(master=addbox, text="SSN:")
label.grid(row=7, column=0, padx=20, pady=10, sticky="ew")
socentry = ctk.CTkEntry(master=addbox, placeholder_text='
111-111-1111')
socentry.grid(row=7, column=1, columnspan=3, padx=20, pady=10,
sticky="ew")
label = ctk.CTkLabel(master=addbox, text="Witholdings:")
label.grid(row=8, column=0, padx=20, pady=10, sticky="ew")
wentry = ctk.CTkEntry(master=addbox, placeholder_text='2')
wentry.grid(row=8, column=1, columnspan=3, padx=20, pady=10, sticky=
"ew")
label = ctk.CTkLabel(master=addbox, text="Salary:")
label.grid(row=9, column=0, padx=20, pady=10, sticky="ew")
salentry = ctk.CTkEntry(master=addbox, placeholder_text='100000')
salentry.grid(row=9, column=1, columnspan=3, padx=20, pady=10,
sticky="ew")
button = ctk.CTkButton(master=addbox, text="Add Employee", command=
addbutton)
button.grid(row=10, column=0, padx=20, pady=30, sticky='ew')
button = ctk.CTkButton(master=addbox, text="Cancel", command=cancel)
button.grid(row=10, column=1, padx=20, pady=30, sticky='ew')
def hover(cell):
edit = ctk.CTkToplevel(root) #The hover function allows for us to
edit and delete certain cells/rows of our table.
edit.title("Edit Data")
edit.geometry("280x140")
edit.focus()
edit.grab_set()
edit_box = ctk.CTkEntry(master=edit, placeholder_text='New Data')
edit_box.grid(row=0, column=0, columnspan=2, padx=20, pady=20,
sticky="ew")
def editcell():
table.insert(cell["row"], cell["column"], value=edit_box.get())
edit.destroy()
def deleterow():
table.delete_row(cell["row"])
edit.destroy()
button = ctk.CTkButton(master=edit, text="Edit Cell", command=
editcell, width=100, height=30)
button.grid(row=1, column=0, padx=20, pady=20, sticky='ew')
button = ctk.CTkButton(master=edit, text="Delete Row", command=
deleterow, width=100, height=30)
button.grid(row=1, column=1, padx=20, pady=20, sticky='ew')
button = ctk.CTkButton(master=new_window, text="Home", command=home,
width=30, height=30)
button.grid(row=0, column=0, padx=20, pady=20, sticky="w")
button = ctk.CTkButton(master=new_window, text="Add Employee", command=
employee_add, width=120, height=30)
button.grid(row=0, column=1, padx=20, pady=20, sticky="e")
label = ctk.CTkLabel(master=new_window, text="Employee Data", font=('
Roboto', 30, 'bold'))
label.grid(row=1, column=0, padx=20, pady=0, sticky="ew", columnspan=2)
#This if statement states the contents of the table. If there is
already data, use the data. If there is not data, display the table heading
only.
if Path('employeevalues.txt').is_file() == False:
value = [['First Name', 'Last Name', 'Address 1', 'Address 2', 'City
', 'State', 'Zip Code', 'SSN', 'Witholdings', 'Salary']]
else:
with open('employeevalues.txt', 'rb') as fp:
b = pickle.load(fp)
value = b
scrollable= ctk.CTkScrollableFrame(master=new_window, width=1260, height
=465) #Scrollable allows for us to scroll if the table goes off screen.
scrollable.grid(padx=10, pady=10, row=2, columnspan=2)
table = CTkTable(master=scrollable, values=value, header_color='
DodgerBlue3', width=124, command=hover, hover_color='#646464', wraplength=
140)
table.grid(padx=0, pady=10, columnspan=2, sticky='ew')
root.withdraw() #This hides the main menu.
…On Sun, Oct 15, 2023 at 7:15 AM Akash Bora ***@***.***> wrote:
@pythoncodingnewbie <https://github.com/pythoncodingnewbie> Show any
example code/image.
—
Reply to this email directly, view it on GitHub
<#51 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BDH5766VM5BERFP7ADMVD5TX7PHURANCNFSM6AAAAAA57IJ6NM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
@pythoncodingnewbie Give a code that I can test directly, analyzing your incomplete code will be very hard and time consuming. |
Beta Was this translation helpful? Give feedback.
0 replies
-
ok it is a large file.
…On Sun, Oct 15, 2023 at 8:10 AM Akash Bora ***@***.***> wrote:
@pythoncodingnewbie <https://github.com/pythoncodingnewbie> Give a code
that I can test directly, analyzing your incomplete code will be very hard
and time consuming.
—
Reply to this email directly, view it on GitHub
<#51 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BDH57657GN65452CAD7ZMALX7POF5ANCNFSM6AAAAAA57IJ6NM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
actually i just solved it while thinking about the layout. I just needed to
specify the width when adding the new row as well.
…On Sun, Oct 15, 2023 at 8:36 AM Matt Koska ***@***.***> wrote:
ok it is a large file.
On Sun, Oct 15, 2023 at 8:10 AM Akash Bora ***@***.***>
wrote:
> @pythoncodingnewbie <https://github.com/pythoncodingnewbie> Give a code
> that I can test directly, analyzing your incomplete code will be very hard
> and time consuming.
>
> —
> Reply to this email directly, view it on GitHub
> <#51 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BDH57657GN65452CAD7ZMALX7POF5ANCNFSM6AAAAAA57IJ6NM>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am making an application which adds data to tables after calling a function. However, the table expands in width from the base width when i add a row. When i leave the toplevel and return it goes back to normal. Is there a way to set a fixed table width?
Beta Was this translation helpful? Give feedback.
All reactions