Code problem in python

my code is saying that there is indentation problems (don’t know how to fix)

Hey @EDWINBENNION, welcome to the forums!

It will be much more easier to help you if you could send us the link to your repl!

do i have to publish it first to share it?

You’ve probably mixed up tabs and spaces somewhere. In python3 everything must be either tabs, or spaces. Try putting your code through a tool like this one:

it now says unindent does not match any outer indentation level

here is the link


import tkinter as tk
from tkinter import colorchooser
from tkinter import filedialog

root = tk.Tk()
txt = tk.Text(root)

def change_color(color):
    txt.tag_configure("color", foreground=color)
    txt.tag_add("color", "sel.first", "sel.last")

color_button = tk.Button(root, text="Change Color", command=lambda: change_color("red"))

def choose_color():
    color = colorchooser.askcolor()
    choose_color_button = tk.Button(root, text="choose color", command=choose_color)

def open_file():
    filepath = filedialog.askopenfilename()
    with open(filepath, 'r') as f:
        content =
    txt.insert(tk.END, content)
def save_file():
    filepath = filedialog.asksaveasfilename(defaultextension='.txt')
    with open(filepath, 'w') as f:
        contents = txt.get("1.0",tk.END)

menubar = tk.Menu(root)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=open_file)
filemenu.add_command(label="Save", command=save_file)
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.