Python Forum
simple file button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple file button
#1
Hi everyone, can you help me, i need a simple file button, to select an image and copy to a some other directory.

Help me please, I have this:

from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilename

root = Tk(  )

#This is where we lauch the file manager bar.
def OpenFile():
    name = askopenfilename(initialdir="C:/Users/",
                           filetypes =(("All files", "*.*")),
                           title = "Choose a file."
                           )

    #Using try in case user types in unknown file or closes without choosing a file.
    try:
        with open(name,'r') as UseFile:
            copy(name,"asd/"+name)
    except:
        print("No file exists")


Title = root.title( "File Opener")
label = ttk.Label(root, text ="I'm BATMAN!!!",foreground="red",font=("Helvetica", 16))
label.pack()

#Menu Bar

menu = Menu(root)
root.config(menu=menu)

file = Menu(menu)

file.add_command(label = 'Open', command = OpenFile)
file.add_command(label = 'Exit', command = lambda:exit())

menu.add_cascade(label = 'File', menu = file)
But I have problemas with the copy function
Reply
#2
What problems do you have?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Button Plays Random .MP3 File From Folder blufacebaby 2 2,046 Feb-05-2021, 02:19 AM
Last Post: BashBedlam
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,951 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Simple Button click on image file to create action? jpezz 4 6,796 Mar-27-2019, 10:08 PM
Last Post: jpezz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020