Python 3 tkcode Library to Display Source Code Blocks and Build Source Code Editor GUI Desktop App Full Project For Beginners

Python 3 tkcode Library to Display Source Code Blocks and Build Source Code Editor GUI Desktop App Full Project For Beginners

 

 

pip install tkcode

 

 

 

 

 

 

app.py

 

 

import tkinter as tk
from tkinter import ttk

from tkcode import CodeBlock

root = tk.Tk()
root.title("CodeBlock example")
root.config(bg="#4e5a65")

style = ttk.Style()

card_im = tk.PhotoImage(file="code_card.png")

style.layout("Card", [("Card.field", {"children": [("Card.padding", {"expand": 1})]})])

style.element_create(
    "Card.field", "image", card_im, border=20, padding=4, sticky="nsew"
)

main_frame = ttk.Frame(root, padding=15, style="Card")
main_frame.pack(fill="both", expand=True, padx=20, pady=20)

code_block = CodeBlock(main_frame, width=42, height=9)
code_block.pack(expand=True, fill="both")

code_block.content = """import tkinter as tk
from tkcode import CodeEditor
root = tk.Tk()
text = CodeEditor(root, language="kotlin")
text.pack(expand=True, fill="both")
root.mainloop()"""

root.update()
root.minsize(root.winfo_width(), root.winfo_height())
root.mainloop()

 

 

 

 

 

 

app.py

 

 

import tkinter as tk
from tkinter import ttk
from tkcode import CodeEditor

root = tk.Tk()
root.title("CodeEditor example")
root.option_add("*tearOff", 0)

menubar = tk.Menu(root)

file_menu = tk.Menu(menubar)
file_menu.add_command(label="New")
file_menu.add_command(label="Open")
file_menu.add_command(label="Save")
file_menu.add_command(label="Save as")
file_menu.add_separator()
file_menu.add_command(label="Exit")

help_menu = tk.Menu(menubar)
help_menu.add_command(label="Help")
help_menu.add_command(label="About")

menubar.add_cascade(menu=file_menu, label="File")
menubar.add_cascade(menu=help_menu, label="Help")

root.config(menu=menubar)

notebook = ttk.Notebook(root)
tab_1 = ttk.Frame(notebook)
notebook.add(tab_1, text="hello.cpp")
notebook.pack(fill="both", expand=True)

code_editor = CodeEditor(
    tab_1,
    width=40,
    height=10,
    language="c++",
    autofocus=True,
    blockcursor=True,
    insertofftime=0,
    padx=10,
    pady=10,
)

code_editor.pack(fill="both", expand=True)

code_editor.content = """#include <iostream>
using namespace std;
int main() {
\tcout << "Hello World!" << endl;
\treturn 0;
}"""


root.update()
root.minsize(root.winfo_width(), root.winfo_height())
root.mainloop()

Leave a Reply