0

i am trying to create a program which detects when someone click a button, so wht i want to do is when the user click the button then the "if" code should be ran, this will duplicate a file. Here is the code i used:

button1=Button(text="duplicate file", fg="green",bg="black")
button1.pack()
if button1 clicked:
    f=open("prototype.txt","rb")
    g=open(f,"wb")

so it might be my code makes no sense after all idk which code to use so does anyone know which code should i use?(the "clicked" keyword is invalid syntax, python says it is. If u know wht to use then pls tell)

  • which GUI framework are you using? – Paul H Dec 22 '20 at 03:48
  • I am using tkinter, i just added a button widget and i used root=Tk for window –  Dec 22 '20 at 03:52
  • I've never used tkinter, but this is pretty high up in the search results for "tkinter button command" https://www.tutorialkart.com/python/tkinter/button/command/ – Paul H Dec 22 '20 at 03:54
  • @Paul H ok thx for it,it worked but i do not understand how to copy data inside one notepad and then move it to the other new file –  Dec 22 '20 at 04:27
  • That is a separate question that has nothing to do with UI and has been answered on this site many times. – Paul H Dec 22 '20 at 05:51

1 Answers1

0

You don't have to write that if statement try:

button1=Button(text="duplicate file", fg="green",bg="black", command = button_clicked)
button1.pack()
def button_clicked:
    f=open("prototype.txt","rb")
    g=open(f,"wb")