I'm having a hard time fetching my data from the uploaded MS Access file. I just want to select and upload .mdb file and then display the data inside the frame according to my query line.
This is my code and I got stuck.
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
def addFile():
filename = filedialog.askopenfilename(initialdir="/", title="Select File", filetypes=(("Microsoft Access", "*.mdb *.accdb"), ("all files", "*.*")))
canvas = tk.Canvas(root, height=500, width=500, bg="#263d42")
canvas.pack()
openFile = tk.Button(root, text="Open File", padx=10, pady=5, fg="#263d42", bg="white", command= addFile)
openFile.pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
root.mainloop()
Related
When I run this code a window pops up and I can upload a video of which I can play/stop/pause the video; however the video will not have sound. Is there any way I can solve this issue? I am new to Python. Thanks.
from tkinter import *
from tkinter.filedialog import askopenfile
from tkVideoPlayer import TkinterVideo
# customtkinter.set_appearance_mode("System") # Modes: system (default), light, dark
# customtkinter.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green
# create box
window = Tk()
# title of the box, not the text in the box
window.title("Tkinter Play Videos in Video Player")
window.geometry("700x450")
window.configure(bg="white")
def open_file():
file = askopenfile(mode='r', filetypes=[
('Video Files', ["*.mp4"])])
if file is not None:
global filename
filename = file.name
global videoplayer
videoplayer = TkinterVideo(master=window, scaled=True)
videoplayer.load(r"{}".format(filename))
videoplayer.pack(expand=True, fill="both")
videoplayer.play()
def playAgain():
print(filename)
videoplayer.play()
def StopVideo():
print(filename)
videoplayer.stop()
def PauseVideo():
print(filename)
videoplayer.pause()
# center this label
lbl1 = Label(window, text="Video Player", bg="white",
fg="blue", font="none 24 bold")
lbl1.config(anchor=CENTER)
lbl1.pack()
openbtn = Button(window, text='Open', command=lambda: open_file())
openbtn.pack(side=TOP, pady=2)
playbtn = Button(window, text='Play Video', command=lambda: playAgain())
playbtn.pack(side=TOP, pady=3)
stopbtn = Button(window, text='Stop Video', command=lambda: StopVideo())
stopbtn.pack(side=TOP, padx=4)
pausebtn = Button(window, text='Pause Video', command=lambda: PauseVideo())
pausebtn.pack(side=TOP, padx=5)
window.mainloop()
The result video does not have audio.
I'm making a simple program that uses tkinter and shutil to copy files, nothing fancy. The problem is that there's no indication of when the process is done, and if I'm copying large folders, the program freezes until it's done copying. I want a progressbar, but don't know how to implement one in tkinter.
from tkinter import *
from tkinter import filedialog
import shutil
def browseFiles():
filename = filedialog.askdirectory(initialdir="/", title="Select a directory")
label_file_explorer.configure(text="Directory Opened: " + filename, bg="grey")
shutil.copytree(filename, r"J:\PCmover\ziptest\test")
window = Tk()
window.title('Beringia')
window.geometry("700x500")
window.config(background="white")
label_file_explorer = Label(window, width=100, height=4, bg="white", fg="blue")
button_explore = Button(window, text="Choose directory", command=browseFiles)
button_exit = Button(window, text="Quit", command=exit)
softwarename=Label(window, text="Welcome to Beringia!", width=100, height=4, fg="blue")
ver=Label(window, text="Ver 1.0", bg="grey", fg="blue")
label_file_explorer.place(x=0, y=200)
button_explore.place(x=305, y=80)
button_exit.place(x=335, y=120)
softwarename.place(x=0, y=0)
ver.place(x=659, y=479)
window.mainloop()
so ok i was just using TKInter when i got this error NameError
name 'runApps' is not defined
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
apps = []
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="#163542")
canvas.pack()
frame = tk.Frame(root, bg="green")
frame.place(relwidth=0.4, relheight=0.4, relx=0.3, rely=0.25)
openFile = tk.Button(root, text="Open File", padx=10,
pady=5, fg="white", bg="#163542" ,command=addApp)
openFile.pack()
runApps = tk.Button(root, text="Run Apps", padx=10,
pady=5 , fg="white", bg="#163542" , command = runApps)
runApps.pack()
root.mainloop()
ok if anyone knows how to fix this make a comment or answer
this section for this post is only for ShanyeLoyd
here is the post you wanted ShanyeLoyd
If you fix the indents in your code then it works.
As per the official documentation:
Leading whitespace (spaces and tabs) at the beginning of a logical
line is used to compute the indentation level of the line, which in
turn is used to determine the grouping of statements.
Correct formatted code:
import tkinter as tk
from tkinter import filedialog
import os
root = tk.Tk()
apps = []
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="#163542")
canvas.pack()
frame = tk.Frame(root, bg="green")
frame.place(relwidth=0.4, relheight=0.4, relx=0.3, rely=0.25)
openFile = tk.Button(
root, text="Open File", padx=10, pady=5, fg="white", bg="#163542", command=addApp
)
openFile.pack()
runApps = tk.Button(
root, text="Run Apps", padx=10, pady=5, fg="white", bg="#163542", command=runApps
)
runApps.pack()
root.mainloop()
GUI:
I am new to tkinter and I am having trouble with buttons on the python GUI. I create the buttons and the function behind it but I am unable to click the button. Can someone tell me what I am doing wrong? The UI comes up and I can see the button I just can't click it.
import tkinter as tk
from tkinter import filedialog, Text
import os
#main
root = tk.Tk()
def addApp():
filename = filedialog.askopenfilename(initialir= "/", title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
canvas = tk.Canvas(root, height=700, width=700, bg="#33F9FF")
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="black",
bg="#33F9FF", command="addApp")
openFile.pack()
runApps = tk.Button(root, text = "Run Apps", padx = 10, pady = 5, fg="black",
bg="#33F9FF")
runApps.pack()
root.mainloop()
Very, small mistake. You added command argument as a string and not a function
openFile = tk.Button(root, text = "Open File", padx = 10, pady = 5, fg="black",
bg="#33F9FF", command=addApp)
EDIT:
there is a small typo at initialdir argument in openfiledialogbox
filename = filedialog.askopenfilename(initialdir= "/", title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
There's also one more mistake:
def addApp():
filename = filedialog.askopenfilename(initialdir= '/', title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
apps = []
def addApp():
for widget in frame.winfo_children():
widget.destroy()
filename = filedialog.askopenfile(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()
root.mainloop()
The function filedialog.askopenfile() returns a file object, not its name. To get the file name, use filedialog.askopenfilename().