From 292be9c61fcb63963368d85a7dc17d9d5c164c1a Mon Sep 17 00:00:00 2001 From: BrianMarquez3 Date: Mon, 28 Sep 2020 13:05:13 -0500 Subject: [PATCH] Python Tkinter Build A text Editor V - Undo Redo and Horizontal Scrollbar start --- .../BuildTextEditorV.py | 177 ++++++++++++++++++ .../documents/documents.html | 55 ++++++ .../documents/documents.txt | 12 ++ .../documents/documents2.txt | 2 + .../documents/documents3.txt | 1 + .../icons/document.ico | Bin 0 -> 67646 bytes 6 files changed, 247 insertions(+) create mode 100644 Python Tkinter Build A text Editor V/BuildTextEditorV.py create mode 100644 Python Tkinter Build A text Editor V/documents/documents.html create mode 100644 Python Tkinter Build A text Editor V/documents/documents.txt create mode 100644 Python Tkinter Build A text Editor V/documents/documents2.txt create mode 100644 Python Tkinter Build A text Editor V/documents/documents3.txt create mode 100644 Python Tkinter Build A text Editor V/icons/document.ico diff --git a/Python Tkinter Build A text Editor V/BuildTextEditorV.py b/Python Tkinter Build A text Editor V/BuildTextEditorV.py new file mode 100644 index 00000000..d88d1a36 --- /dev/null +++ b/Python Tkinter Build A text Editor V/BuildTextEditorV.py @@ -0,0 +1,177 @@ +# Python Tkinter Build A text Editor V - Undo Redo and Horizontal Scrollbar +# Python Tkinter Build A editor de texto + +from tkinter import * +from tkinter import filedialog +from tkinter import font + +root = Tk() +root.title('Python Tkinter Build A text Editor V') +root.iconbitmap('Python Tkinter Build A text Editor V/icons/document.ico') +root.geometry("1000x660") + +# Set Variable for opne file name +global open_status_name +open_status_name = False + +global selected +selected = False + +# Create New File Function +def new_file(): + # Delete previos text + my_text.delete("1.0", END) + # Update status bars + root.title("New File - TextPad!") + status_bar.config(text="New File ") + + global open_status_name + open_status_name = False + +# Open Files +def open_file(): + # Delete Precios Text + my_text.delete("1.0", END) + + # Grab Filename + text_file = filedialog.askopenfilename(initialdir="Python Tkinter Build A text Editor V/documents/", title="Open File", filetypes=(("Text Files", "*.txt"), ("HTML Files", "*.html"), ("Python Files", "*.py"), ("All Files", "*.*"))) + + # Check to see if there is a file name + if text_file: + # Make filename global so we can access it later + global open_status_name + open_status_name = text_file + + # Updaet status bars + name = text_file + status_bar.config(text=f'{name} ') + name = name.replace("C:/Users/brian/Documents/Python-Course/Python Tkinter Build A text Editor V/documents/", "") + root.title(f'{name} - TextPad!') + + # Open the File + text_file = open(text_file, 'r') + stuff = text_file.read() + + # Close the opened file + text_file.close() + + # Add File textbox + my_text.insert(END, stuff) + +#Save as file +def save_as_file(): + text_file = filedialog.asksaveasfilename(defaultextension=".*", initialdir="C:/Users/brian/Documents/Python-Course/Python Tkinter Build A text Editor V/documents/", title="Save File", filetypes=(("Text Files", "*.txt"), ("HTML Files", "*.html"), ("Python Files", "*.py"), ("All Files", "*.*"))) + if text_file: + # Updates Status Bars + name = text_file + status_bar.config(text=f'{name} ') + name = name.replace("C:/Users/brian/Documents/Python-Course/Python Tkinter Build A text Editor V/documents/", "") + root.title(f'{name} - TextPad!') + + # Save File + text_file = open(text_file, "w") + text_file.write(my_text.get(1.0, END)) + #close the file + text_file.close() + +# Save File +def save_file(): + global open_status_name + if open_status_name: + # Save File + text_file = open(open_status_name, "w") + text_file.write(my_text.get(1.0, END)) + #close the file + text_file.close() + # put status + status_bar.config(text=f'{open_status_name} ') + else: + save_as_file() + +# cut Text +def cut_text(e): + global selected + + if e: + selected = root.clipboard_get() + + else: + if my_text.selection_get(): + selected = my_text.selection_get() + # Delected selected text from box + my_text.delete("sel.first", "sel.last") + #clear the clipboard then append + root.clipboard_clear() + root.clipboard_append(selected) + +# copy Text +def copy_text(e): + global selected + #CHECK TO SEE IF WE USED KEYBOARD SHORTCUTS + if e: + selected = root.clipboard_get() + + if my_text.selection_get(): + # Grab selected text from text box + selected = my_text.selection_get() + root.clipboard_clear() + root.clipboard_append(selected) + +# paste Text +def paste_text(e): + global selected + if e: + selected = root.clipboard_get() + else: + if selected: + position = my_text.index(INSERT) + my_text.insert(position, selected) + + +# Creare Main Frame +my_frame = Frame(root) +my_frame.pack(pady=5) + +# Create our Scrollbar For the Text Box +text_scroll = Scrollbar(my_frame) +text_scroll.pack(side=RIGHT, fill=Y) + +# Create Text Box +my_text = Text(my_frame, width=97, height=25, font=("Helvetica", 16), selectbackground="#4FDECD", selectforeground="black", undo=True, yscrollcommand=text_scroll.set) +my_text.pack() + +# Configure our Scroolbar +text_scroll.config(command=my_text.yview) + +# Create Menu +my_menu = Menu(root) +root.config(menu=my_menu) + +#A Add File Menu +file_menu = Menu(my_menu, tearoff=False) +my_menu.add_cascade(label="File", menu=file_menu) +file_menu.add_command(label="New", command=new_file) +file_menu.add_command(label="Open", command=open_file) +file_menu.add_command(label="Save", command=save_file) +file_menu.add_command(label="Save As", command=save_as_file) +file_menu.add_command(label="Exit", command=root.quit) + +# Add Edit Menu +edit_menu = Menu(my_menu, tearoff=False) +my_menu.add_cascade(label="Edit", menu=edit_menu) +edit_menu.add_command(label="Cut (Ctrl+x)", command=lambda: cut_text(False)) +edit_menu.add_command(label="Copy (Ctrl+c)", command=lambda: copy_text(False)) +edit_menu.add_command(label="Paste (Ctrl+v)", command=lambda: paste_text(False)) +edit_menu.add_command(label="Undo") +edit_menu.add_command(label="Redo") + +# Add Status Bar To Botton of App +status_bar = Label(root, text="Ready ", anchor=E) +status_bar.pack(fill=X, side=BOTTOM, ipady=5) + +# Edit Bindings +root.bind('', cut_text) +root.bind('', copy_text) +root.bind('', paste_text) + +root.mainloop() diff --git a/Python Tkinter Build A text Editor V/documents/documents.html b/Python Tkinter Build A text Editor V/documents/documents.html new file mode 100644 index 00000000..a0035b1e --- /dev/null +++ b/Python Tkinter Build A text Editor V/documents/documents.html @@ -0,0 +1,55 @@ + + + + + + Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
HoyMañanaLunes
SoleadoMayormente soleadoParcialmente nublado
19°C17°C12°C
E 13 km/hE 11 km/hS 16 km/h
+ + + \ No newline at end of file diff --git a/Python Tkinter Build A text Editor V/documents/documents.txt b/Python Tkinter Build A text Editor V/documents/documents.txt new file mode 100644 index 00000000..3ff339ad --- /dev/null +++ b/Python Tkinter Build A text Editor V/documents/documents.txt @@ -0,0 +1,12 @@ +#---------------------------# +hello Brian date +#---------------------------# + + +Using Python TKinter + +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. + +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. + + diff --git a/Python Tkinter Build A text Editor V/documents/documents2.txt b/Python Tkinter Build A text Editor V/documents/documents2.txt new file mode 100644 index 00000000..9f98ef39 --- /dev/null +++ b/Python Tkinter Build A text Editor V/documents/documents2.txt @@ -0,0 +1,2 @@ +this is document2 text + diff --git a/Python Tkinter Build A text Editor V/documents/documents3.txt b/Python Tkinter Build A text Editor V/documents/documents3.txt new file mode 100644 index 00000000..6fdf84e4 --- /dev/null +++ b/Python Tkinter Build A text Editor V/documents/documents3.txt @@ -0,0 +1 @@ +documents3 diff --git a/Python Tkinter Build A text Editor V/icons/document.ico b/Python Tkinter Build A text Editor V/icons/document.ico new file mode 100644 index 0000000000000000000000000000000000000000..3a7b3dda07b8b6d8e8cd3d1d4161dc4e7ee899d4 GIT binary patch literal 67646 zcmeI5dvH_NoyWz{Svs?wp%WlLl9qJS@K`cwnm~ah#JqwHw9_FC?Iv{7%(go_EPv#W z{IQ$OX3cJzCO{?zY-57~lkhevuRv%*jEs2`z`Pt|8!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