I’m building an Image to PDF converter app using python. When I run the code in the terminal the UI doesn’t appear. Here is the code:
`import tkinter as tk
from tkinter import filedialog, messagebox
import os
class ImageToPdfConverter:
def __init__(self, root):
self.root = root
self.image_paths = []
self.output_pdf_name = tk.StringVar()
self.selected_image_listbox = tk.Listbox(root, selectmode=tk.MULTIPLE)
self.initialize_ui()
def initialize_ui(self):
title_label = tk.Label(self.root, text = "Image to PDF Converter", font=("Helvetica", 16,
"bold"))
title_label.pack(pady=10)
def main():
root = tk.Tk()
root.title("Image to PDF")
root.geometry("400x600")
root.mainloop()
if __name__== "__main__":
main()`
When I click "Run Python File in Terminal", it runs however the UI does not show up.
2
Answers
The indentation of the
main
function at the end of the code is incorrect and should be changed to the followingyour code looks just fine but at the end the indentation of
if __name__== "__main__": main()
is incorrect.
Here’s your fixed code that will generate the tkinter GUI: