I'm making an application that allows the user to enter in information for sales at a party hire store and I've come across an issue.
Edit: I've tried using sticky and many other placement tools but nothing has seemed to work so far.
When I append more than one set of data to my dictionary and then press the print results button, all of the entered data is really close to each other.
Here is the code:
# Party Gear Hire Shop
from tkinter import *
# Makes graphics better, if causing issues feel free to remove (up to dashed line) #
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(True)
# ---------------------------------------------------------------------------------#
# Data
# Table where dataNeeded is kept
dataNeeded = {}
type(dataNeeded)
dataNeeded["Position"] = []
dataNeeded["fName"] = []
dataNeeded["lName"] = []
dataNeeded["item"] = []
dataNeeded["amount"] = []
trackerNum = 0
# Commands
def doAppend():
global trackerNum
global dataNeeded
trackerNum += 1
dataNeeded["Position"] += [trackerNum]
dataNeeded["fName"] += [nameFirstEntry.get()]
dataNeeded["lName"] += [nameLastEntry.get()]
dataNeeded["item"] += [itemHiredEntry.get()]
dataNeeded["amount"] += [amountHiredEntry.get()]
def doPrintResults():
resultsWindow = Toplevel(root)
resultsWindow.title("Receipts")
resultsFrame = LabelFrame(resultsWindow, text="Current Receipts", padx=10, pady=10)
resultsFrame.grid(row=0, column=0, columnspan=3, rowspan=5, padx=10, pady=10)
resultsHeader = Label(resultsFrame, text="Receipt No:", padx=2.5, pady=2.5)
resultsHeader.grid(row=0, column=0, padx=2.5, pady=2.5)
resultsHeader1 = Label(resultsFrame, text="First Name:", padx=2.5, pady=2.5)
resultsHeader1.grid(row=1, column=0, padx=2.5, pady=2.5)
resultsHeader1_5 = Label(resultsFrame, text="Last Name:", padx=2.5, pady=2.5)
resultsHeader1_5.grid(row=2, column=0, padx=2.5, pady=2.5)
resultsHeader2 = Label(resultsFrame, text="Item:", padx=2.5, pady=2.5)
resultsHeader2.grid(row=3, column=0, padx=2.5, pady=2.5)
resultsHeader3 = Label(resultsFrame, text="Quantity:", padx=2.5, pady=2.5)
resultsHeader3.grid(row=4, column=0, padx=2.5, pady=2.5)
rowPlacement = -1
for x in dataNeeded:
rowPlacement += 1
nameLabel = Label(resultsFrame, text=dataNeeded[x], padx=2.5, pady=2.5)
nameLabel.grid(column=trackerNum+1, row=rowPlacement, padx=2.5, pady=2.5)
root = Tk()
root.title("Party Hire Store") # Titles window
# Entry Area -----------------------------------------------------------------------------------------------------------
entryAreaFrame = LabelFrame(root, text="Add a transaction", padx=10, pady=10)
entryAreaFrame.grid(row=0, column=0, columnspan=3, rowspan=5, padx=10, pady=10)
nameFirstLabel = Label(entryAreaFrame, text="First Name:")
nameFirstLabel.grid(row=0, column=0, padx=1, pady=1)
nameFirstEntry = Entry(entryAreaFrame)
nameFirstEntry.grid(row=0, column=1, columnspan=2, rowspan=1, padx=1, pady=1)
nameLastLabel = Label(entryAreaFrame, text="Last Name:")
nameLastLabel.grid(row=1, column=0, padx=1, pady=1)
nameLastEntry = Entry(entryAreaFrame)
nameLastEntry.grid(row=1, column=1, columnspan=2, rowspan=1, padx=1, pady=1)
itemHiredLabel = Label(entryAreaFrame, text="Item Hired:")
itemHiredLabel.grid(row=2, column=0, padx=1, pady=1)
itemHiredEntry = Entry(entryAreaFrame)
itemHiredEntry.grid(row=2, column=1, columnspan=2, rowspan=1, padx=1, pady=1)
amountHiredLabel = Label(entryAreaFrame, text="Quantity:")
amountHiredLabel.grid(row=3, column=0, padx=1, pady=1)
amountHiredEntry = Entry(entryAreaFrame)
amountHiredEntry.grid(row=3, column=1, columnspan=2, rowspan=1, padx=1, pady=1)
doAppendButton = Button(entryAreaFrame, text="Append Details", padx=2.5, pady=2.5, command=doAppend)
doAppendButton.grid(row=4, column=0, padx=5, pady=5)
doPrintButton = Button(entryAreaFrame, text="Print Receipt", padx=2.5, pady=2.5, command=doPrintResults)
doPrintButton.grid(row=4, column=1, padx=5, pady=5, columnspan=2)
root.mainloop()
Now, what I'm asking for is how to make it so that for any piece of data that is entered, When I print the results, it prints neatly on a new window, which can be closed separately.
However, any other suggestions or improvements would be greatly appreciated as I look to further my skills in python, and in programming as a whole so any help is useful.
Thanks!
Related
so is it possible to make a python gui that can input data into a one drive shared excel spreadsheet ? and if so please can someone help me as this is my code so far
from numbers import Number
import tkinter
from tkinter import ttk
def enter_data():
Cardnumber = Card_number_entry.get()
Year = Year_entry.get()
Name = Name_entry.get()
Set = Set_entry.get()
Refractor = Refractor_entry.get()
Cert = Cert_entry.get()
Grade = Grade_entry.get()
print("Card Number:", Cardnumber)
print("Year:", Year)
print("Name:", Name)
print("Set:", Set)
print("Refractor:", Refractor)
print("Cert:", Cert)
print("Grade:", Grade)
window = tkinter.Tk()
window.title("MGC POPULATION REPORT")
frame = tkinter.Frame(window)
frame.pack()
card_info_frame =tkinter.LabelFrame(frame, text="Card Infomation")
card_info_frame.grid(row=0, column=0, padx=300, pady=35)
Card_number_label = tkinter.Label(card_info_frame, text="Card Number")
Card_number_label.grid(row=0, column=0, padx=10, pady=1)
Year_label = tkinter.Label(card_info_frame, text="Year")
Year_label.grid(row=2, column=0, padx=10, pady=1)
Name_label = tkinter.Label(card_info_frame, text="Name")
Name_label.grid(row=4, column=0, padx=10, pady=1)
Set_label = tkinter.Label(card_info_frame, text="Set")
Set_label.grid(row=6, column=0, padx=10, pady=1)
Refractor_label = tkinter.Label(card_info_frame, text="Refractor")
Refractor_label.grid(row=8, column=0, padx=10, pady=1)
Cert_label = tkinter.Label(card_info_frame, text="Certification (#)")
Cert_label.grid(row=10, column=0, padx=10, pady=1)
Grade_label = tkinter.Label(card_info_frame, text="Grade")
Grade_label.grid(row=12, column=0, padx=10, pady=1)
Card_number_entry = tkinter.Entry(card_info_frame)
Year_entry = tkinter.Entry(card_info_frame)
Name_entry = tkinter.Entry(card_info_frame)
Set_entry = tkinter.Entry(card_info_frame)
Refractor_entry = tkinter.Entry(card_info_frame)
Cert_entry = tkinter.Entry(card_info_frame)
Grade_entry = tkinter.Entry(card_info_frame)
Card_number_entry.grid(row=1, column=0)
Year_entry.grid(row=3, column=0)
Name_entry.grid(row=5, column=0)
Set_entry.grid(row=7, column=0)
Refractor_entry.grid(row=9, column=0)
Cert_entry.grid(row=11, column=0)
Grade_entry.grid(row=13, column=0)
button = tkinter.Button(frame, text="Enter Data", command= enter_data)
button.grid(row=15, column=0, sticky="news", padx=300, pady=35)
window.mainloop()
i dont even know where to start lol, so is it possible to make a python gui that can input data into a one drive shared excel spreadsheet ? and if so please can someone help me as this is my code so far
This is my code:
mycanvas = Canvas(self.search_result_frame)
mycanvas.pack(side=LEFT)
yscrollbar = ttk.Scrollbar(self.search_result_frame, orient="vertical", command=mycanvas.yview)
yscrollbar.pack(side=RIGHT, fill=Y)
mycanvas.configure(yscrollcommand=yscrollbar.set)
mycanvas.bind('<Configure>', lambda e: mycanvas.configure(scrollregion = mycanvas.bbox('all')))
self.sample_frame = Frame(mycanvas)
mycanvas.create_window((0,0), window=self.sample_frame, anchor=E)
for widget in self.search_result_frame.winfo_children():
widget.destroy()
if len(matching_bills) > 0:
for bill in matching_bills:
with open(f'{self.bill_folder}//{bill}//data//bill_details.json', 'r') as bill_json_file:
bill_details = json.loads(bill_json_file.read())
customer_name = bill_details["customer_details"][0]
payment_method = bill_details["payment_method"]
date_of_issue = bill_details["date_of_issue"]
date_of_issue = datetime.strptime(date_of_issue, "%d/%m/%Y")
date_of_issue = date_of_issue.strftime("%d %b %Y")
# # -------------------- Search Result Frame Contents
result_frame = Frame(self.sample_frame, bg=self.bg3, bd=5, relief=GROOVE)
result_frame.pack(fill=BOTH, pady=2)
result_billno_lbl = Label(result_frame, text=bill, bg=self.bg1, fg="#FFF", font=self.search_results_font1, padx=22, pady=3)
result_billno_lbl.grid(row=0, column=0, padx=50, pady=8, sticky=W)
billed_to_lbl = Label(result_frame, text=f"Billed To - {customer_name}", bg=self.bg1, fg="#FFF", font=self.search_results_font2, bd=2, relief=RAISED, padx=12, pady=3)
billed_to_lbl.grid(row=0, column=1, padx=80, sticky=W)
billed_type_lbl = Label(result_frame, text=f"Bill Type - {payment_method}", bg=self.bg1, fg="#FFF", font=self.search_results_font2, bd=2, relief=RAISED, padx=12, pady=3)
billed_type_lbl.grid(row=0, column=2, sticky=W)
issued_on_lbl = Label(result_frame, text=f"Issued On - {date_of_issue}", bg=self.bg1, fg="#FFF",
font=self.search_results_font2, bd=2, relief=RAISED, padx=12, pady=3)
issued_on_lbl.grid(row=0, column=3, padx=80, sticky=W)
view_btn = Button(result_frame, text="View", font="Comicsan 14", bd=2, relief=GROOVE, bg="#000", fg="#FFF", padx=1, command=lambda bill=bill: self.view_bill(bill))
view_btn.grid(row=0, column=4, padx=3, columnspan=2, sticky=W)
elif len(matching_bills) == 0:
for widgets in self.search_result_frame.winfo_children():
widgets.destroy()
no_result_lbl = Label(self.search_result_frame, text=f"No search result found for {bill_cat}", font=self.search_results_font1, bg=self.bg3, fg="#FFF")
no_result_lbl.pack(fill=X)
When I run it, it shows me the bad window path name ".!labelframe.!canvas.!frame error and when I try to do the same thing without object-oriented in tkinter then it works well !
I want to create a BMI calculator program with Tkinter but I'm stuck at calculation procedure
I use StringVar() to keep user data to calculate but I don't know how to calculate
this my code :
from tkinter import *
def mainwindow():
main = Tk()
main.geometry("300x400")
main.title("BMI")
main.rowconfigure((0,1,2,3,4), weight=1)
main.columnconfigure(0, weight=1)
main.config(bg="green")
main.option_add("*Font", "times 15 bold")
return main
def createframe(main):
Label(main, text="BMI APP", bg="lightgreen").grid(row=0, column=0, sticky=N)
frame_1 = Frame(main, bg="white")
frame_1.grid(row=1, column=0, sticky="NEWS", padx=10, pady=10, ipady=5)
frame_2 = Frame(main, bg="white")
frame_2.grid(row=2, column=0, sticky="NEWS", padx=10, pady=10, ipady=5)
frame_3 = Frame(main, bg="white")
frame_3.grid(row=3, column=0, sticky="NEWS", padx=10, pady=10, ipady=20)
frame_bottom = Frame(main, bg="white")
frame_bottom.grid(row=4, column=0, sticky="NEWS", padx=10, pady=10, ipady=20)
frame_bottom.columnconfigure(0, weight=0)
frame_bottom.columnconfigure(1, weight=2)
return frame_1, frame_2, frame_3, frame_bottom
def widget(frame_1, frame_2, frame_3, frame_bottom):
Label(frame_1, text="HEIGHT:(cm.)").grid(row=0, column=0, padx=5, pady=5, sticky=W)
ent_height = Entry(frame_1, bg="pink", textvariable=height_var)
ent_height.grid(row=1, column=0, ipadx=40, padx=10, sticky=N+W)
Label(frame_2, text="WEIGHT:(kg.)").grid(row=0, column=0, padx=5, pady=5, sticky=W)
ent_weight = Entry(frame_2, bg="lightblue", textvariable=weight_var)
ent_weight.grid(row=1, column=0, ipadx=40, padx=10, sticky=N+W)
Button(frame_bottom, text="Calculate", highlightbackground="lightgreen", fg="white", command=find_bmi).grid(row=2, column=1)
show_data = Label(frame_bottom, bg="white")
return ent_height, ent_weight
def find_bmi():
global bmi
bmi = 0
height = height_var.get()
weight = weight_var.get()
height = float(height) / 100.0
bmi = float(weight) / height ** 2
print("BMI = %0.2f" % bmi)
bmi = 0
main = mainwindow()
height_var = StringVar()
height_var.set("1")
weight_var = StringVar()
weight_var.set("1")
frame_1, frame_2, frame_3, frame_bottom = createframe(main)
ent_height, ent_weight = widget(frame_1, frame_2, frame_3, frame_bottom)
find_bmi()
main.mainloop()
I try to set a new value and calculate it because StringVar() can't calculate itself but when I use it that way I have to set the default to 1 if I don't set it will error ZeroDivisionError: float division by zero I don't want to set a number first if I set the first user will see that number
the frame_3 is used to show BMI to the user when calculating completed
You can check to see if the height and weight inputs have been filled in before doing the conversion/calculation.
from tkinter import *
def mainwindow():
main = Tk()
main.geometry("300x400")
main.title("BMI")
main.rowconfigure((0,1,2,3,4), weight=1)
main.columnconfigure(0, weight=1)
main.config(bg="green")
main.option_add("*Font", "times 15 bold")
return main
def createframe(main):
Label(main, text="BMI APP", bg="lightgreen").grid(row=0, column=0, sticky=N)
frame_1 = Frame(main, bg="white")
frame_1.grid(row=1, column=0, sticky="NEWS", padx=10, pady=10, ipady=5)
frame_2 = Frame(main, bg="white")
frame_2.grid(row=2, column=0, sticky="NEWS", padx=10, pady=10, ipady=5)
frame_3 = Frame(main, bg="white")
frame_3.grid(row=3, column=0, sticky="NEWS", padx=10, pady=10, ipady=20)
frame_bottom = Frame(main, bg="white")
frame_bottom.grid(row=4, column=0, sticky="NEWS", padx=10, pady=10, ipady=20)
frame_bottom.columnconfigure(0, weight=0)
frame_bottom.columnconfigure(1, weight=2)
return frame_1, frame_2, frame_3, frame_bottom
def widget(frame_1, frame_2, frame_3, frame_bottom):
Label(frame_1, text="HEIGHT:(cm.)").grid(row=0, column=0, padx=5, pady=5, sticky=W)
ent_height = Entry(frame_1, bg="pink", textvariable=height_var)
ent_height.grid(row=1, column=0, ipadx=40, padx=10, sticky=N+W)
Label(frame_2, text="WEIGHT:(kg.)").grid(row=0, column=0, padx=5, pady=5, sticky=W)
ent_weight = Entry(frame_2, bg="lightblue", textvariable=weight_var)
ent_weight.grid(row=1, column=0, ipadx=40, padx=10, sticky=N+W)
Label(frame_3, text="BMI").grid(row=0, column=0, padx=5, pady=5,sticky=W)
show_data = Label(frame_3)
show_data.grid(row=1, column=0, ipadx=40, padx=10, sticky=N+W)
Button(frame_bottom, text="Calculate", highlightbackground="lightgreen", fg="white", command=find_bmi).grid(row=2, column=1)
return ent_height, ent_weight, show_data
def find_bmi():
height = height_var.get()
weight = weight_var.get()
# check height and weight filled in
if height and weight:
height = float(height) / 100.0
bmi = round(float(weight) / height ** 2, 2)
show_data.config(text = bmi)
else:
show_data.config(text='')
main = mainwindow()
height_var = StringVar()
weight_var = StringVar()
frame_1, frame_2, frame_3, frame_bottom = createframe(main)
ent_height, ent_weight, show_data = widget(frame_1, frame_2, frame_3, frame_bottom)
main.mainloop()
I am mainly coding on my MAC.
I created a GUI that is used for a tool I am using to automate things with selenium.
I have used .grid for all widgets in my GUI.
But when I open the GUI on my Windows laptop at home (same resolution but much smaller monitor panel) it is totally messed up.
Here are two screenshot showing the problem,
Messed up layout on Win Laptop (17,3")
The second screenshot shows how it should look.
This is the code I used for the grid layout:
# General GUI settings
app = Tk()
app.title('trade_buddy')
app.geometry('605x800')
app.minsize(605, 800)
app.maxsize(605, 800)
app.grid_rowconfigure(0, weight=1)
app.grid_rowconfigure(1, weight=1)
app.grid_rowconfigure(2, weight=1)
app.grid_rowconfigure(3, weight=1)
app.grid_rowconfigure(4, weight=1)
app.grid_rowconfigure(5, weight=1)
app.grid_rowconfigure(6, weight=1)
app.grid_rowconfigure(7, weight=1)
app.grid_rowconfigure(8, weight=1)
app.grid_rowconfigure(9, weight=1)
app.grid_rowconfigure(10, weight=1)
app.grid_rowconfigure(11, weight=1)
app.grid_rowconfigure(12, weight=1)
app.grid_rowconfigure(13, weight=1)
#Background label
image = Image.open('v2.0/lolo.png')
image = image.resize((600,450), Image.ANTIALIAS)
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = tk.Label(app, image = photo)
label.place(x=0, y=0)
#Buttons
b_init = tk.Button(app,text='Initialize',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10, command=lambda:threading.Thread(target=tb,daemon=True).start())
b_exit = tk.Button(app,text='Exit',font='Tahoma 10 bold',padx=8,bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d', pady=10,command=lambda:threading.Thread(target=exit_tb,daemon=True).start())
b_start = tk.Button(app,text='Start',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=filters,daemon=True).start())
b_pause = tk.Button(app,text='Pause',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=stop_tb,daemon=True).start())
b_tfm = tk.Button(app,text='TFM',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=tfm,daemon=True).start())
#Labels
l_maxBO = tk.Label(app,text='Maximum buy price:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
l_itemsontf = tk.Label(text='# of items on transfer list:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
l_speed = tk.Label(text='Choose speed:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10 bold')
l_routine = tk.Label(text='Choose routine:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10 bold')
#Entries
e_maxBO = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d', font='Tahoma 10')
e_itemsontf = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
e_fixedsellprice = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
#Text box
t_outputbox = tk.Text(app, width=99, height=27, font='Tahoma 10',bg='#2c2c2c', fg='#f8f09d', relief=SUNKEN, highlightthickness="1")
#Grid Layout
l_maxBO.grid(row=0, column=0, sticky='w', padx=5, pady=5)
l_itemsontf.grid(row=1, column=0, sticky='w', padx=5, pady=5)
l_speed.grid(row=3, column=0, sticky='w', padx=5, pady=1, ipady=1)
l_routine.grid(row=7, column=0, sticky='w', padx=5, pady=1, ipady=1)
e_maxBO.grid(row=0, column=1, sticky='w', padx=5, pady=5)
e_itemsontf.grid(row=1, column=1, sticky='w', padx=5, pady=5)
e_fixedsellprice.grid(row=11, column=0, sticky='w', padx=5, pady=3)
b_exit.grid(row=12, column=8, sticky='sw', padx=5, pady=10)
b_init.grid(row=12, column=4, sticky='sw', padx=5, pady=10)
b_start.grid(row=12, column=0, sticky='sw', padx=5, pady=10)
b_pause.grid(row=12, column=1, sticky='sw', padx=5, pady=10)
b_tfm.grid(row=12, column=2, sticky='sw', padx=5, pady=10)
r_normal.grid(row=4, column=0, sticky='w', padx=5, pady=1)
r_fast.grid(row=5, column=0, sticky='w', padx=5, pady=1)
r_slow.grid(row=6, column=0, sticky='w', padx=5, pady=1)
r_buyonly.grid(row=8, column=0, sticky='w', padx=5, pady=1)
r_fullroutine.grid(row=9, column=0, sticky='w', padx=5, pady=1)
r_buysellfixed.grid(row=10, column=0, sticky='w', padx=5, pady=1)
t_outputbox.grid(row=13, column=0, columnspan=13, rowspan=13, sticky='nsew', padx=5, pady=10)
As a coding beginner, I really have no idea what else I could change.
I already changed from .place to .grid but the problem is still the same.
Does anyone have an idea how I could setup my GUI that it keeps the minimum required geometry relations no matter on what monitor I work?
Here is an example of forcing it to look like the second picture.
import tkinter as tk
from PIL import ImageTk, Image
# General GUI settings
app = tk.Tk()
app.configure(bg="black")
#Background label
image = Image.open('test.png')
image = image.resize((200,200), Image.ANTIALIAS)
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = tk.Label(app, image = photo)
label.grid(row=3, column=1, sticky='w')
#others
r_normal = tk.Radiobutton(app, text="Normal Speed")
r_fast = tk.Radiobutton(app, text="Fast Speed")
r_slow = tk.Radiobutton(app, text="Slow Speed")
r_buyonly = tk.Radiobutton(app, text="Buy only")
r_fullroutine = tk.Radiobutton(app, text="Full routine (optimized price)")
r_buysellfixed = tk.Radiobutton(app, text="Buy and sell for fixed price")
#Buttons
b_init = tk.Button(app,text='Initialize',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10, command=lambda:threading.Thread(target=tb,daemon=True).start())
b_exit = tk.Button(app,text='Exit',font='Tahoma 10 bold',padx=8,bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d', pady=10,command=lambda:threading.Thread(target=exit_tb,daemon=True).start())
b_start = tk.Button(app,text='Start',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=filters,daemon=True).start())
b_pause = tk.Button(app,text='Pause',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=stop_tb,daemon=True).start())
b_tfm = tk.Button(app,text='TFM',font='Tahoma 10 bold',bg='#f8f09d',fg='#1e1e1f',activebackground='#1e1e1f',activeforeground='#f8f09d',padx=8, pady=10,command=lambda:threading.Thread(target=tfm,daemon=True).start())
#Labels
l_maxBO = tk.Label(app,text='Maximum buy price:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
l_itemsontf = tk.Label(text='# of items on transfer list:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
l_speed = tk.Label(text='Choose speed:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10 bold')
l_routine = tk.Label(text='Choose routine:',bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10 bold')
#Entries
e_maxBO = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d', font='Tahoma 10')
e_itemsontf = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
e_fixedsellprice = tk.Entry(app, width=10, bg='#1e1e1f', fg='#f8f09d',font='Tahoma 10')
#Text box
t_outputbox = tk.Text(app, width=99, height=27, font='Tahoma 10',bg='#2c2c2c', fg='#f8f09d', relief=tk.SUNKEN, highlightthickness="1")
#Grid Layout
l_maxBO.grid(row=0, column=0, sticky='w', padx=5, pady=5)
l_itemsontf.grid(row=1, column=0, sticky='w', padx=5, pady=5)
l_speed.grid(row=3, column=0, sticky='w', padx=5, pady=1, ipady=1)
l_routine.grid(row=7, column=0, sticky='w', padx=5, pady=1, ipady=1)
e_maxBO.grid(row=0, column=1, sticky='w', padx=5, pady=5)
e_itemsontf.grid(row=1, column=1, sticky='w', padx=5, pady=5)
e_fixedsellprice.grid(row=11, column=0, sticky='w', padx=5, pady=3)
b_exit.grid(row=12, column=8, sticky='sw', padx=5, pady=10)
b_init.grid(row=12, column=4, sticky='sw', padx=5, pady=10)
b_start.grid(row=12, column=0, sticky='sw', padx=5, pady=10)
b_pause.grid(row=12, column=1, sticky='sw', padx=5, pady=10)
b_tfm.grid(row=12, column=2, sticky='sw', padx=5, pady=10)
r_normal.grid(row=4, column=0, sticky='w', padx=5, pady=1)
r_fast.grid(row=5, column=0, sticky='w', padx=5, pady=1)
r_slow.grid(row=6, column=0, sticky='w', padx=5, pady=1)
r_buyonly.grid(row=8, column=0, sticky='w', padx=5, pady=1)
r_fullroutine.grid(row=9, column=0, sticky='w', padx=5, pady=1)
r_buysellfixed.grid(row=10, column=0, sticky='w', padx=5, pady=1)
t_outputbox.grid(row=13, column=0, columnspan=13, rowspan=13, sticky='nsew', padx=5, pady=10)
Notable differences:
I had to set a background color to make up for how we are moving that image.
The image is no longer using .place and instead using .grid.
The image will need to be resized a bit differently because it is a smaller area.
I removed all those row_configures because they were removing some rigidity, you can add it back if you like, but you'll have to re-scale your columns to match the new layout.
Let us know if you have any questions etc.
I have a Toplevel Window with one grid row containing a Label, Entry and a "+" Button (window on startup)
When I hit the Add-Button a new row with the same content is generated. But the problem is, that the window doesn't resize and fit to its new contents. Should look like this resized window.
The code is below:
def process_map():
numbers = {0:'\u2080', 1:'\u2081', 2:'\u2082', 3:'\u2083', 4:'\u2084', 5:'\u2085', 6:'\u2086', 7:'\u2087', 8:'\u2088', 9:'\u2089'}
button_pos = tk.IntVar(0)
ENTRIES = {}
def add_button():
if button_pos.get() >= 10:
index = numbers[button_pos.get()//10] + numbers[button_pos.get()%10]
else:
index = numbers[button_pos.get()]
lb = tk.Label(top_root, text='\u03C6'+index)
lb.grid(row=button_pos.get(), column=0, sticky='NWES')
entry = tk.Entry(top_root, width=4, relief='sunken', bd=2)
entry.grid(row=button_pos.get(), column=1, sticky='WE', padx=5, pady=5)
ENTRIES.update({button_pos.get():entry})
bt.grid(row=button_pos.get(), column=2, sticky='WE', padx=5, pady=5)
bt_close.grid(row=button_pos.get()+1, column=1, padx=5, pady=5)
bt_start.grid(row=button_pos.get()+1, column=0, padx=5, pady=5)
button_pos.set(button_pos.get()+1)
center(top_root)
top_root = tk.Toplevel(root)
top_root.title('Select \u03C6')
lb = tk.Label(top_root, text='\u03C6\u2081', height=1)
lb.grid(row=0, column=0, sticky='NWES')
entry = tk.Entry(top_root, width=4, relief='sunken', bd=2)
entry.grid(row=0, column=1, sticky='WE', padx=5, pady=5)
button_pos.set(button_pos.get()+2)
ENTRIES.update({button_pos.get():entry})
bt = tk.Button(top_root, text='+', command=add_button,)
bt.grid(row=0, column=2, sticky='WE', padx=5, pady=5)
bt_close = tk.Button(top_root, text='Cancel', width=15, command=top_root.destroy)
bt_close.grid(row=button_pos.get()+1, column=1, padx=5, pady=5)
bt_start = tk.Button(top_root, text='Start', width=15)
bt_start.grid(row=button_pos.get()+1, column=0, padx=5, pady=5)
center(top_root)
top_root.mainloop()