I am developing program to load up files and perform some calculations with those loaded files.
For that I wrote a simple iteration code to load the tkinter variables. The window, label, entry and button positions are already done. So far the code I have is:
import tkinter as tk
from tkinter import ttk, filedialog
LARGE_FONT = ("Arial", 12)
MEDIUM_FONT = ("Arial", 11)
REGULAR_FONT = ("Arial", 10)
text_z = ["Select file 1", "Select the file 2", "Select file 3", "Select file 4"]
window=tk.Tk()
def click():
z = tk.filedialog.askopenfilename(initialdir = "/",title = "Select file", filetypes = ( ("Excel file", "*.xlsx"), ("All files", "*.*") ) )
a[i-2].insert(tk.END, z)
z[i] = a[i-2].get()
##Main program
#There is an image I will add at the end on row=0
ttk.Label(window, text="file load", font = LARGE_FONT, background = "white").grid(row=1, column=1, columnspan=3, padx=20, pady = 10, sticky="W")
a = [tk.StringVar(window) for i in range(len(text_z))]
for i in range(2,len(text_z)+2):
Label_z = ttk.Label(window, text=text_z[i-2], background="white").grid(row= 2*i, column=0,columnspan=3, padx=10, pady=2, sticky="W")
a[i-2] = ttk.Entry(window, width=60, background="gray")
a[i-2].grid(row= 2*i+1, column=0, columnspan=3, padx=10, sticky="WE")
ttk.Button(window, text="Search", width=10, command=click).grid(row= 2*i+1, column=3, padx=5, sticky="W")
window.mainloop()
My problem is on the click button. It was supposed to during a click run the askopenfilename, get the file path and present on the entrybox, but all the buttons direct that to the last created Entrybox.
Can someone help me with this issue?
Thanks alot!
Lambda to the rescue. One needs to know the right Button-Entry pair to update. So pass the value of the corresponding index when a button is pressed.
import tkinter as tk
from tkinter import ttk, filedialog
LARGE_FONT = ("Arial", 12)
MEDIUM_FONT = ("Arial", 11)
REGULAR_FONT = ("Arial", 10)
text_z = ["Select file 1", "Select the file 2", "Select file 3", "Select file 4"]
window=tk.Tk()
def click(m):
z = tk.filedialog.askopenfilename(initialdir = "~",title = "Select file", filetypes = ( ("Text files", "*.txt"), ("All files", "*.*") ) )
a[m].insert(tk.END, z)
ttk.Label(window, text="file load", font = LARGE_FONT, background = "white").grid(row=1, column=1, columnspan=3, padx=20, pady = 10, sticky="W")
a = [None for i in range(len(text_z))]
for i in range(2,len(text_z)+2):
Label_z = ttk.Label(window, text=text_z[i-2], background="white").grid(row= 2*i, column=0,columnspan=3, padx=10, pady=2, sticky="W")
a[i-2] = ttk.Entry(window, width=60, background="gray")
a[i-2].grid(row= 2*i+1, column=0, columnspan=3, padx=10, sticky="WE")
ttk.Button(window, text="Search", width=10, command=lambda m=i-2:click(m)).grid(row= 2*i+1, column=3, padx=5, sticky="W")
window.mainloop()
I think you should simplify things a bit by use a list to store your entry fields.
To do this I think it would be best to add frames for each set of widgets and to use the index of range to get what we need.
I have changed up your code a little to make it easier to work with list index as well as added a button that will print out each selected path on each entry field to show these values are accessible.
import tkinter as tk
from tkinter import ttk, filedialog
LARGE_FONT = ("Arial", 12)
MEDIUM_FONT = ("Arial", 11)
REGULAR_FONT = ("Arial", 10)
text_z = ["Select file 1", "Select the file 2", "Select file 3", "Select file 4"]
window = tk.Tk()
def click(x):
z = tk.filedialog.askopenfilename(initialdir="/", title="Select file", filetypes=(("Excel file", "*.xlsx"), ("All files", "*.*")))
a[x].insert(tk.END, z)
ttk.Label(window, text="file load", font=LARGE_FONT, background="white").grid(row=1, column=0, padx=20, pady=10, sticky="w")
a=[]
for i in range(len(text_z)):
frame = tk.Frame(window)
frame.grid(row=i+2, column=0, sticky="nsew")
ttk.Label(frame, text=text_z[i], background="white").grid(row=0, column=0, columnspan=3, padx=10, pady=2, sticky="w")
a.append(ttk.Entry(frame, width=60, background="gray"))
a[i].grid(row=1, column=0, columnspan=3, padx=10, sticky="ew")
ttk.Button(frame, text="Search", width=10, command=lambda x=i: click(x)).grid(row=1, column=3, padx=5, sticky="w")
def pring_current_paths():
for ndex, entry in enumerate(a):
print("Entry {}: ".format(ndex, entry.get()))
tk.Button(window, text="Print gurrent paths!", command=pring_current_paths).grid()
window.mainloop()
Related
I'm working on a text editor application in Python tkinter. Every time a font is set, it is appended to a list. One of the features of the text editor is managing the font of the text. The issue is that after I change the font in one of the entry boxes, the next time I click on the Font button, The entry boxes input resets to its default input. Can someone help me find a solution for this issue? My code:
import tkinter as tk
from tkinter.filedialog import askopenfilename, asksaveasfilename
import tkinter.font as tkfont
from tkinter import messagebox
window = tk.Tk()
window.title("Text Editor")
window.configure(bg="white")
window.state("zoomed")
count = -1
my_list = []
def open_file():
file_path = askopenfilename(filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if not file_path:
return
text_box.delete("1.0", tk.END)
with open(file_path, "r") as file_read:
text = file_read.read()
text_box.insert(tk.END, text)
def save_file():
file_path = asksaveasfilename(defaultextension="txt", filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if not file_path:
return
with open(file_path, "w") as file_write:
text = text_box.get(1.0, tk.END)
file_write.write(text)
def font_command(default_font):
global count
count += 1
window2 = tk.Toplevel(window)
window2.title("Font Name")
window2.geometry("300x220+500+200")
font_n = tk.Label(window2, text="Font:", font=("Arial Rounded MT Bold", 10))
font_n.place(x=50, y=80)
name_entry = tk.Entry(window2)
name_entry.place(x=50, y=110)
font_size = tk.Label(window2, text="Font Size:", font=("Arial Rounded MT Bold", 10))
font_size.place(x=50, y=20)
size_entry = tk.Entry(window2)
size_entry.place(x=50, y=50)
font_color = tk.Label(window2, text="Font Color:", font=("Arial Rounded MT Bold", 10))
font_color.place(x=50, y=140)
color_entry = tk.Entry(window2)
color_entry.place(x=50, y=170)
color_entry.delete(0, tk.END)
color_entry.insert(tk.END, text_box["fg"])
ok_button = tk.Button(window2, text="OK", width=8, height=2, bg="white",
command=lambda: check_font(size_entry.get(), name_entry.get(), color_entry.get(), window2))
ok_button.place(x=210, y=100)
if count == 0:
name_entry.delete(0, tk.END)
name_entry.insert(tk.END, default_font["family"])
size_entry.delete(0, tk.END)
size_entry.insert(tk.END, default_font["size"])
my_list.append((name_entry.get(), size_entry.get()))
else:
name_entry.delete(0, tk.END)
name_entry.insert(tk.END, my_list[count - 1][0])
size_entry.delete(0, tk.END)
size_entry.insert(tk.END, my_list[count - 1][1])
my_list.append((name_entry.get(), size_entry.get()))
def check_font(size, font, color, root):
try:
font_settings = tkfont.Font(family=font, size=size)
text_box.configure(fg=color, font=font_settings)
root.destroy()
except:
messagebox.showerror("Font Error", "Invalid Font!")
frame = tk.Frame(window, bd=2, relief="raised")
frame.pack(side="left", fill="y")
default_f = tkfont.Font(family="Courier New", size=10)
text_box = tk.Text(window, font=default_f, fg="black")
text_box.pack(side="left", fill="both", expand=True)
scroll_bar = tk.Scrollbar(window, command=text_box.yview)
scroll_bar.pack(side="left", fill="y")
open_b = tk.Button(frame, text="Open", width=6, height=2, bg="white", command=open_file)
open_b.pack(padx=50, pady=(100, 5), anchor="n")
save_b = tk.Button(frame, text="Save As", width=6, height=2, bg="white", command=save_file)
save_b.pack(padx=50, pady=5)
font_info = tk.Button(frame, text="Font", width=6, height=2, bg="white", command=lambda: font_command(default_f))
font_info.pack(padx=50, pady=5)
text_box.configure(yscrollcommand=scroll_bar.set)
clear_text = tk.Button(frame, text="Clear All", width=6, height=2, bg="white",
command=lambda: text_box.delete(0, tk.END))
clear_text.pack(padx=50, pady=5)
window.mainloop()
I've managed to solve the problem with the help of #TheLizzard! The changes that I've made: I moved the my_list.append((font, size)) part to the try clause in the check_file function because I wanted to append the font attributes to the list only after the OK button was clicked, rather than right after creating the widgets in the font_command function. In the except clause, I'm also decrementing count by 1, so that if a user inputs a font which throws an error, it won't be counted.
Code:
import tkinter as tk
from tkinter.filedialog import askopenfilename, asksaveasfilename
import tkinter.font as tkfont
from tkinter import messagebox
window = tk.Tk()
window.title("Text Editor")
window.configure(bg="white")
window.state("zoomed")
count = -1
my_list = []
def open_file():
file_path = askopenfilename(filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if not file_path:
return
text_box.delete("1.0", tk.END)
with open(file_path, "r") as file_read:
text = file_read.read()
text_box.insert(tk.END, text)
def save_file():
file_path = asksaveasfilename(defaultextension="txt", filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
if not file_path:
return
with open(file_path, "w") as file_write:
text = text_box.get(1.0, tk.END)
file_write.write(text)
def font_command(default_font):
global count
count += 1
window2 = tk.Toplevel(window)
window2.title("Font Name")
window2.geometry("300x220+500+200")
font_n = tk.Label(window2, text="Font:", font=("Arial Rounded MT Bold", 10))
font_n.place(x=50, y=80)
name_entry = tk.Entry(window2)
name_entry.place(x=50, y=110)
font_size = tk.Label(window2, text="Font Size:", font=("Arial Rounded MT Bold", 10))
font_size.place(x=50, y=20)
size_entry = tk.Entry(window2)
size_entry.place(x=50, y=50)
font_color = tk.Label(window2, text="Font Color:", font=("Arial Rounded MT Bold", 10))
font_color.place(x=50, y=140)
color_entry = tk.Entry(window2)
color_entry.place(x=50, y=170)
color_entry.delete(0, tk.END)
color_entry.insert(tk.END, text_box["fg"])
ok_button = tk.Button(window2, text="OK", width=8, height=2, bg="white",
command=lambda: check_font(size_entry.get(), name_entry.get(), color_entry.get(), window2))
ok_button.place(x=210, y=100)
if count == 0:
name_entry.delete(0, tk.END)
name_entry.insert(tk.END, default_font["family"])
size_entry.delete(0, tk.END)
size_entry.insert(tk.END, default_font["size"])
else:
name_entry.delete(0, tk.END)
name_entry.insert(tk.END, my_list[count - 1][0])
size_entry.delete(0, tk.END)
size_entry.insert(tk.END, my_list[count - 1][1])
def check_font(size, font, color, root):
global count
try:
font_settings = tkfont.Font(family=font, size=size)
text_box.configure(fg=color, font=font_settings)
root.destroy()
my_list.append((font, size))
except:
messagebox.showerror("Font Error", "Invalid Font!")
count -= 1
frame = tk.Frame(window, bd=2, relief="raised")
frame.pack(side="left", fill="y")
default_f = tkfont.Font(family="Courier New", size=10)
text_box = tk.Text(window, font=default_f, fg="black")
text_box.pack(side="left", fill="both", expand=True)
scroll_bar = tk.Scrollbar(window, command=text_box.yview)
scroll_bar.pack(side="left", fill="y")
open_b = tk.Button(frame, text="Open", width=6, height=2, bg="white", command=open_file)
open_b.pack(padx=50, pady=(100, 5), anchor="n")
save_b = tk.Button(frame, text="Save As", width=6, height=2, bg="white", command=save_file)
save_b.pack(padx=50, pady=5)
font_info = tk.Button(frame, text="Font", width=6, height=2, bg="white", command=lambda: font_command(default_f))
font_info.pack(padx=50, pady=5)
text_box.configure(yscrollcommand=scroll_bar.set)
clear_text = tk.Button(frame, text="Clear All", width=6, height=2, bg="white",
command=lambda: text_box.delete("1.0", tk.END))
clear_text.pack(padx=50, pady=5)
window.mainloop()
I want to code a searchable ttk.Treeview; however, my code does not behave properly. When I type in and click search nothing happens. What should be improved so the searched items are highlighted when I type in?
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Medicine database")
def add():
tree.insert("",END,values=("",e1.get()))
def search(item=''):
children = tree.get_children(item)
for child in children:
text = tree.item(child, 'text')
if text.startswith(e1.get()):
tree.selection_set(child)
return True
else:
res = search(child)
if res:
return True
lb1 = Label(root,text="Search:")
lb1.grid(row =0,column=0,padx=10,pady=10,sticky=W)
e1=Entry(root,width=15)
e1.grid(row=0,column=1,padx=10,pady=10,sticky=E,rowspan=1)
btn = Button(root,text="search",width=10,command=search)
btn.grid(row =0,column=0,padx=10,pady=10,rowspan=2)
btn1 = Button(root,text="add",width=10,command=add)
btn1.grid(row =1,column=0,padx=10,pady=10,rowspan=2)
#treeview
tree = ttk.Treeview(root,height=25)
tree["columns"]=("one","two","three","four")
tree.column("one",width=120)
tree.column("two",width=160)
tree.column("three",width=130)
tree.column("four",width=160)
tree.heading("one", text="Numer seryjny leku")
tree.heading("two", text="Nazwa Leku")
tree.heading("three", text="Ampułki/Tabletki")
tree.heading("four",text="Data ważności")
tree["show"]="headings"
tree.grid(row=0,column=2,rowspan=6,pady=20)
root.geometry("840x580")
root.mainloop()
As it was, your search method did nothing.
First, you probably need to have an entry for adding items and another for searching them.
Then, in the search method, you must retrieve the query from the search entry, match it with then tree children values, and return (here we will print) the values if you find a match, and highlight them in the Treeview.
import tkinter as tk
from tkinter import ttk
def add():
value = add_entry.get()
values.append(value)
tree.insert("", tk.END, values=(f'#{len(values)}', value, 'more', 'moar'))
def search():
query = search_entry.get()
selections = []
for child in tree.get_children():
if query in tree.item(child)['values']:
print(tree.item(child)['values'])
selections.append(child)
print('search completed')
tree.selection_set(selections)
values = []
root = tk.Tk()
root.title("Medicine database")
lb1 = tk.Label(root, text="Search:")
lb1.grid(row=0, column=0, padx=10, pady=10, sticky=tk.W)
search_entry = tk.Entry(root, width=15)
search_entry.grid(row=0, column=1, padx=10, pady=10, sticky=tk.E, rowspan=1)
btn = tk.Button(root, text="search", width=10, command=search)
btn.grid(row=0, column=0, padx=10, pady=10, rowspan=2)
add_lb = tk.Label(root, text="add:")
add_lb.grid(row=1, column=0, padx=10, pady=10, sticky=tk.W)
add_entry = tk.Entry(root, width=15)
add_entry.grid(row=1, column=1, padx=10, pady=10, sticky=tk.E, rowspan=1)
btn1 = tk.Button(root, text="add", width=10, command=add)
btn1.grid(row=1, column=0, padx=10, pady=10, rowspan=2)
# treeview
tree = ttk.Treeview(root, height=25)
tree["columns"] = ("one", "two", "three", "four")
tree.column("one", width=120)
tree.column("two", width=160)
tree.column("three", width=130)
tree.column("four", width=160)
tree.heading("one", text="Numer seryjny leku")
tree.heading("two", text="Nazwa Leku")
tree.heading("three", text="Ampułki/Tabletki")
tree.heading("four", text="Data ważności")
tree["show"]="headings"
tree.grid(row=0, column=2, rowspan=6, pady=20)
root.geometry("840x580")
if __name__ == '__main__':
root.mainloop()
from tkinter import *
def tell_story(Male):
story= "My name is" + "Male"
Frame.story_txt.delete(0.0, END)
Frame.story_txt.insert(0.0, story)
root = Tk()
root.title("game")
root.geometry("800x400")
Application = Frame(root)
Application.grid()
Lbl1 = Label(Application, text="story").grid(row=0, column=0, sticky=W)
Lbl2 = Label(Application, text="Male name").grid(row=1, column=0, sticky=W)
Male = Entry(Application).grid(row=1, column=1, sticky=W)
Button(Application, text="Click for story", command=tell_story).grid(row=11, column=0, sticky=W)
Frame.story_txt = Text(Application, width=75, height=10, wrap=WORD)
Frame.story_txt.grid(row=12, column=0, columnspan=4)
root.mainloop()
I'm unable to print story variable in text widget
In the code given below, I want to create a GUI in such a way that 1) In the top frame: 1st row : "x"(checkbutton), right to "x"(checkbutton) must be "Choose xFile"(button) and right to "Choose xFile"(button) must be "clear"(button) and likewise in the 2nd row : for "y". Only when the "x" checkbutton is checked, the "choose xFile" button should gets enabled. And when clicked upon "choose xFile", it has to open the file dialogbox. And the choosen file contents should get displayed using "description box" below the "Input data"(label) in the middle frame(with both horizontal and vertical scrollbar). And when "clear" button is clicked, only the selected file contents(x or y file choosen) in the "description box" must be cleared and it must enable the "Choose xFile"(button) or "Choose yFile"(button) to perform the task again(i.e to open the file dialog box). Below to the "description box" must contain "Reset" button and to the right of "Reset" button must be "Submit" button in the middle portion of the middle frame. When the "Reset" button is clicked, all the contents being displayed in the "description box" must be cleared and the all the checkboxes must be unchecked so that the user can perform the selection process again. In the bottom frame, below "Model Output"(label), a "description box" along with "horizontal" and "vertical" scrollbar must be there. Below to the "description box" must contain "Exit" button which is placed in the middle of the "bottom frame".
from tkinter import *
def forButton1():
filename1 = askopenfilename()
with open(filename1) as f:
for i in f:
myList.insert(END, i)
print(filename1)
def forButton2():
filename1 = askopenfilename()
with open(filename1) as f:
for i in f:
myList.insert(END, i)
print(filename1)
def forButton7():
root.destroy()
root = Tk()
root.title("Spatialization of DSSAT")
topFrame = LabelFrame(root, text = "Select input file")
MyVar1 = IntVar()
MyVar2 = IntVar()
MyCheckbutton1 = Checkbutton(topFrame, text="x", variable=MyVar1)
#MyCheckbutton1.grid(row=0, column=0)
MyCheckbutton1.pack()
MyCheckbutton2 = Checkbutton(topFrame, text="y", variable=MyVar2)
#MyCheckbutton2.grid(row=1, column=0)
MyCheckbutton2.pack()
Button1 = Button(topFrame, text = "Choose xFile", command = forButton1)
#button1.grid(row=0, column=1)
Button1.pack()
Button2 = Button(topFrame, text = "Choose yFile", command = forButton2)
#button2.grid(row=0, column=1)
Button2.pack()
Button3 = Button(topFrame, text = "Clear")
Button3.pack()
Button4 = Button(topFrame, text = "Clear")
Button4.pack()
topFrame.pack(side=TOP)
middleFrame = Frame(root)
label1 = Label(middleFrame, text = "Input data:")
label1.grid(row = 4)
scrollbar = Scrollbar(middleFrame)
myList = Listbox(middleFrame, yscrollcommand = scrollbar.set)
myList.pack()
scrollbar.config( command = myList.yview )
scrollbar.pack()
Button5 = Button(middleFrame, text = "Reset")
#button1.grid(row=0, column=1)
Button5.pack()
Button6 = Button(middleFrame, text = "Submit")
#button1.grid(row=0, column=1)
Button6.pack()
middleFrame.pack()
bottomFrame = Frame(root)
label2 = Label(bottomFrame, text = "Model Output:")
label2.grid(row = 10)
Button7 = Button(bottomFrame, text = "Exit", command = forButton7)
#button1.grid(row=0, column=1)
Button7.pack()
bottomFrame.pack()
root.geometry("500x500")
root.mainloop()
Here I have fixed the placement of the given widgets (not their functionalities) as asked in question. You can follow this way to get your desired format:
from tkinter import *
from tkinter import filedialog
def forButton1():
filename1 = filedialog.askopenfilename()
with open(filename1) as f:
for i in f:
myList.insert(END, i)
print(filename1)
def forButton2():
filename1 = filedialog.askopenfilename()
with open(filename1) as f:
for i in f:
myList.insert(END, i)
print(filename1)
def forButton7():
root.destroy()
root = Tk()
root.title("Spatialization of DSSAT")
root.grid_columnconfigure(0, weight=1)
topFrame = LabelFrame(root, text="Select input file")
topFrame.grid(row=0, column=0, padx=8, pady=8, sticky=N+E+S+W)
topFrame.grid_rowconfigure(0, weight=1)
topFrame.grid_rowconfigure(1, weight=1)
topFrame.grid_columnconfigure(0, weight=1)
topFrame.grid_columnconfigure(1, weight=1)
topFrame.grid_columnconfigure(2, weight=1)
middleFrame = LabelFrame(root, text="Input data")
middleFrame.grid(row=1, column=0, padx=8, pady=8, sticky=N+E+S+W)
middleFrame.grid_rowconfigure(0, weight=1)
middleFrame.grid_rowconfigure(1, weight=0)
middleFrame.grid_columnconfigure(0, weight=1)
middleFrame.grid_columnconfigure(1, weight=1)
bottomFrame = LabelFrame(root, text="Model Output")
bottomFrame.grid(row=2, column=0, padx=8, pady=8, sticky=N+E+S+W)
bottomFrame.grid_rowconfigure(0, weight=1)
bottomFrame.grid_columnconfigure(0, weight=1)
MyVar1 = IntVar()
MyVar2 = IntVar()
MyCheckbutton1 = Checkbutton(topFrame, text="x", variable=MyVar1)
MyCheckbutton1.grid(row=0, column=0, padx=4, pady=4)
Button1 = Button(topFrame, text="Choose xFile", command=forButton1)
Button1.grid(row=0, column=1, padx=4, pady=4)
Button3 = Button(topFrame, text="Clear")
Button3.grid(row=0, column=2, padx=4, pady=4)
MyCheckbutton2 = Checkbutton(topFrame, text="y", variable=MyVar2)
MyCheckbutton2.grid(row=1, column=0, padx=4, pady=4)
Button2 = Button(topFrame, text="Choose yFile", command=forButton2)
Button2.grid(row=1, column=1, padx=4, pady=4)
Button4 = Button(topFrame, text="Clear")
Button4.grid(row=1, column=2, padx=4, pady=4)
innerMiddleFrame = Frame(middleFrame)
innerMiddleFrame.grid(row=0, column=0, columnspan=2, padx=4, pady=4)
innerMiddleFrame.grid_columnconfigure(0, weight=1)
innerMiddleFrame.grid_columnconfigure(1, weight=0)
scrollbar = Scrollbar(innerMiddleFrame)
myList = Listbox(innerMiddleFrame, yscrollcommand=scrollbar.set)
myList.grid(row=0, column=0, sticky=N+E+S+W)
scrollbar.config(command=myList.yview)
scrollbar.grid(row=0, column=1, sticky=N+E+S+W)
Button5 = Button(middleFrame, text="Reset")
Button5.grid(row=1, column=0, padx=4, pady=4)
Button6 = Button(middleFrame, text="Submit")
Button6.grid(row=1, column=1, padx=4, pady=4)
Button7 = Button(bottomFrame, text="Exit", command=forButton7)
Button7.grid(row=0, column=0, padx=4, pady=4)
root.geometry("250x425")
root.mainloop()
How to display the inserted text one by one after pressing a button in Python Tk GUI? I ran the following program successfully but it fills all inserted texts together at the end of the last text. I want to update the text field accordingly by the order of the inserted text. Anyone can help? Thanks.
from Tkinter import *
root = Tk()
root.geometry("300x400")
def startProgram(shapefile_path):
t1 = "testing on file 0 successfull\n"
text.insert('1.0', t1)
t2 = "testing on file 1 successfull\n"
text.insert('1.0', t2)
t3 = "testing on file2 successfull\n"
text.insert('1.0', t3)
text = Text(root, height=8, width=25)
text.grid(row=10, column=0, padx=20, pady=5)
label = Label(root, text="Status",font=12)
label.grid(row=9, column=0, padx=5, pady=5)
button2=Button(root,text="Start Program", width=20,font=12,command=lambda: startProgram(0))
button2.grid(row=7, column=0, padx=20, pady=10)
button3=Button(root, text='Exit Program', width=20,font=12,command=root.destroy)
button3.grid(row=8, column=0,padx=20, pady=10)
root.mainloop()
From what I understand you want to reverse the order of insertions? If so, than instead of 1.0 you can use INSERT:
from Tkinter import *
root = Tk()
root.geometry("300x400")
message_list = ["testing on file 0 successfull\n",
"testing on file 1 successfull\n",
"testing on file2 successfull\n"]
message_list_idx = 0;
def startProgram():
global message_list_idx
if message_list_idx >= len(message_list):
return
t3 = message_list[message_list_idx]
text.insert('1.0', t3)
message_list_idx += 1
text = Text(root, height=8, width=25)
text.grid(row=10, column=0, padx=20, pady=5)
label = Label(root, text="Status",font=12)
label.grid(row=9, column=0, padx=5, pady=5)
button2=Button(root,text="Start Program", width=20,font=12,
command=startProgram)
button2.grid(row=7, column=0, padx=20, pady=10)
button3=Button(root, text='Exit Program',width=20,font=12,
command=root.destroy)
button3.grid(row=8, column=0,padx=20, pady=10)
root.mainloop()
button2=Button(root,text="Start Program", width=20,font=12,
command=startProgram)
button2.grid(row=7, column=0, padx=20, pady=10)
button3=Button(root, text='Exit Program',width=20,font=12,
command=root.destroy)
button3.grid(row=8, column=0,padx=20, pady=10)
root.mainloop()