-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python Tkinter Build A text Editor V - Undo Redo and Horizontal Scrol…
…lbar start
- Loading branch information
1 parent
50935d6
commit 292be9c
Showing
6 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
Python Tkinter Build A text Editor V/BuildTextEditorV.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<Control-Key-x>', cut_text) | ||
root.bind('<Control-Key-c>', copy_text) | ||
root.bind('<Control-Key-v>', paste_text) | ||
|
||
root.mainloop() |
55 changes: 55 additions & 0 deletions
55
Python Tkinter Build A text Editor V/documents/documents.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
|
||
<table class="egt"> | ||
|
||
<tr> | ||
|
||
<th>Hoy</th> | ||
|
||
<th>Mañana</th> | ||
|
||
<th>Lunes</th> | ||
|
||
</tr> | ||
|
||
<tr> | ||
|
||
<td>Soleado</td> | ||
|
||
<td>Mayormente soleado</td> | ||
|
||
<td>Parcialmente nublado</td> | ||
|
||
</tr> | ||
|
||
<tr> | ||
|
||
<td>19°C</td> | ||
|
||
<td>17°C</td> | ||
|
||
<td>12°C</td> | ||
|
||
</tr> | ||
|
||
<tr> | ||
|
||
<td>E 13 km/h</td> | ||
|
||
<td>E 11 km/h</td> | ||
|
||
<td>S 16 km/h</td> | ||
|
||
</tr> | ||
|
||
</table> | ||
|
||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
Python Tkinter Build A text Editor V/documents/documents.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
Python Tkinter Build A text Editor V/documents/documents2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
this is document2 text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
documents3 |
Binary file not shown.