1

This is what I have so far:

tkinter.py

from tkinter import *
import tkinter.filedialog
import os
import sys


root = Tk()
root.title('Download File')
root.iconbitmap('C:/Users/londo/Downloads/tkinter/Logo.ico')
root.geometry("800x600")
pyexec = sys.executable


def resize():
    root.geometry("800x800")

myLabel = Label(root, text="Rename the file to what ever you want, and download it!")
myLabel.pack(pady=20)

def open():
    PathPy = tkinter.filedialog.askopenfilename(title="Open a file",file=[('downloadtkinter.py')])
    os.system('%s %s' % (pyexec, PathPy))

my_button = Button(root, text="Download", command=open)
my_button.pack(pady=20)


root.mainloop()

Error:

Traceback (most recent call last):
  File "D:\Users\londo\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\londo\Downloads\tkinter\tkintertest2.py", line 21, in open
    PathPy = tkinter.filedialog.askopenfilename(title="Open a file",file=[('downloadtkinter.py')])
  File "D:\Users\londo\AppData\Local\Programs\Python\Python39\lib\tkinter\filedialog.py", line 384, in askopenfilename
    return Open(**options).show()
  File "D:\Users\londo\AppData\Local\Programs\Python\Python39\lib\tkinter\commondialog.py", line 46, in show
    s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: bad file type "downloadtkinter.py", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"

downloadtkinter.py

from tkinter as tk
import os


frame = tk.Tk()
frame.title('Download File Here')
frame.iconbitmap('C:/Users/londo/Downloads/tkinter/Logo.ico')
frame.geometry("800x800")


def resize():
    root.geometry("800x800")

def printInput():
    inp = inputtxt.get(1.0, "end-1c")
    lbl.config(text = "Provided Input: "+inp)

myLabel = Label(root, text="Rename the file to what ever you want, and download it!")
myLabel.pack(pady=20)


inputtxt = tk.Text(frame,
                hight = 1,
                width = 20)
inputtxt.pack()


printButton = tk.Button(frame,
                        text = "Print",
                        command = printInput)
printButton.pack()

lbl = tk.Label(frame, text = "")
lbl.pack()
frame.mainloop()

I don't know how to change the file name with the text in the text box and upload a file, please let me know if it's even possible. Thanks, London (I am very new to tkinter and this project might be too advanced for my skill level)

  • 1
    Don't use `tkinter.py` as the name of your script. – acw1668 Oct 21 '21 at 00:29
  • The error tells you exactly what the issue is. You need to use something like `filetypes=[("Python Script", "*.py")]` instead of `file=[("downloadtkinter.py")]`. – acw1668 Oct 21 '21 at 00:50

1 Answers1

1

If you just want to rename a file you can use:

import os
os.rename(firstname,newname)

from here:How to rename a file using Python

Revilo123
  • 11
  • 5