r/pythonhelp • • Jun 15 '22

Why my program doesn't display or have those two buttons despite my code being exactly the same as this guy on Youtube by using the same editor as well?

Hi, I'm trying to make this application from a video on Youtube called "Build A Python GUI App Tutorial" by Dev ed. However, it doesn't show me the buttons. I have also tried it with other IDE's too!

Build A Python GUI App Tutorial - YouTube

import tkinter as tk
from tkinter import filedialog, Text
import os

 
root = tk.Tk()
apps = []

if os.path.isfile('save.txt'):
with open('save.txt', 'r') as f:
        tempApps = f.read()
        tempApps = tempApps.split(',')
        apps = [x for x in tempApps if x.strip()]

def addApp():
for widget in frame.winfo_children():
        widget.destroy()

    filename= filedialog.askopenfilename(initialdir="/",title="Select File",
                                         filetypes =(("executables","*.exe"), ("all files", "*.*")))

    apps.append(filename)
    print(filename)
for app in apps:
        label = tk.label(frame, text=app, bg="gray")
        label.pack()

def runApps():
for app in apps:
        os.startfile(app)

canvas = tk.Canvas(root, height=700, width=700, bg="#263D42")
canvas.pack()

frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)

openFile = tk.Button(root, text="Open File", padx=10, pady=5, fg="white", bg="#263D42", command=addApp)
openFile.pack()

runApps = tk.Button(root, text="Run Apps", padx=10, pady=5, fg="white", bg="#263D42", command=runApps)
runApps.pack()

for app in apps:
    label = tk.Label(frame, text=app)
    label.pack

root.mainloop()
with open('save.txt', 'w') as f:
for app in apps:
        f.write(app + ',')

0 Upvotes

6 comments sorted by

1

u/AmongstYou666 Jun 15 '22

Break down the code into simpler chunks that you understand and that will run, then start adding to it piece by piece. Then look up the chatter on reddit about how to paste code.

import tkinter as tk
root = tk.Tk()
def doop():
    print('wutever')
openFile = tk.Button(root, text="Open File", padx=10, pady=5, fg="white", bg="#263D42", command=doop)
openFile.pack()
runApps = tk.Button(root, text="Run Apps", padx=10, pady=5, fg="white", bg="#263D42", command=doop)
runApps.pack()
root.mainloop()

1

u/HungryButNotFoolish Jun 16 '22

Sorry, but what this code that you have typed is all about? my question was how come my program doesn't display or have those two buttons?

1

u/AmongstYou666 Jun 16 '22

The most basic part of your code is the two buttons, if you don't understand how to fix your code then start from the basics.

1

u/HungryButNotFoolish Jun 17 '22

But why it doesn't show me those two buttons? Did I miss anything in my code or the problem is something else?

1

u/AmongstYou666 Jun 17 '22

It would take me hours to go thru that code to figure out what it actually does.

1

u/HungryButNotFoolish Jun 29 '22

But I have already checked my code twice, from what I've seen it looks like is exactly the same! Do you have any ideas why?