Posts: 59
Threads: 9
Joined: Apr 2019
import os
import sys
import tkinter as tk
from tkinter import *
import subprocess
import idlelib
import urllib.request
import ctypes
import functools
from tkinter import PhotoImage
import webbrowser
from tkinter import messagebox
def base():
root = tk.Tk()
root.geometry("540x540")
messagebox.showinfo(" INFORMAÇÃO","PROGRAMA DE ACESSO RÁPIDO\n\nBASTA CLICAR EM *OK*")
def word():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["WINWORD.exe"])
else:
return
imagetest = PhotoImage(file="word.png")
button_qwer = tk.Button(root, image=imagetest, command=word)
button_qwer.grid(row=1, column=1)
def excel():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["EXCEL.exe"])
else:
return
imagetest2 = PhotoImage(file="excel.png")
button_qwer2 = tk.Button(root, image=imagetest2, command=excel)
button_qwer2.grid(row=1, column=2)
def powerpoint():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["POWERPNT.exe"])
else:
return
imagetest3 = PhotoImage(file="powerpoint.png")
button_qwer3 = tk.Button(root, image=imagetest3, command=powerpoint)
button_qwer3.grid(row=1, column=3)
def publisher():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["MSPUB.exe"])
else:
return
imagetest4 = PhotoImage(file="publisher.png")
button_qwer4 = tk.Button(root, image=imagetest4, command=publisher)
button_qwer4.grid(row=1, column=4)
def outlook():
if True:
webbrowser.open('https://login.live.com/')
else:
return
imagetest5 = PhotoImage(file="outlook.png")
button_qwer5 = tk.Button(root, image=imagetest5, command=outlook)
button_qwer5.grid(row=2, column=1)
def gmail():
if True:
webbrowser.open('https://accounts.google.com/ServiceLogin/identifier?hl=pt-PT&passive=true&continue=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dgooglw%26ie%3D%26oe%3D&flowName=GlifWebSignIn&flowEntry=AddSession')
else:
return
imagetest6 = PhotoImage(file="gmail.png")
button_qwer6 = tk.Button(root, image=imagetest6, command=gmail)
button_qwer6.grid(row=2, column=2)
def notepad():
if True:
path = "C:/WINDOWS/system32/"
os.chdir(path)
subprocess.run(["notepad.exe"])
else:
return
imagetest7 = PhotoImage(file="notepad.png")
button_qwer7 = tk.Button(root, image=imagetest7, command=notepad)
button_qwer7.grid(row=2, column=3)
def meteorologia():
if True:
webbrowser.open('https://www.google.com/search?q=meteorologia&ie=&oe=')
else:
return
imagetest8 = PhotoImage(file="meteorologia.png")
button_qwer8 = tk.Button(root, image=imagetest8, command=meteorologia)
button_qwer8.grid(row=2, column=4)
def google():
if True:
webbrowser.open('https://www.google.pt/')
else:
return
imagetest9 = PhotoImage(file="google.png")
button_qwer9 = tk.Button(root, image=imagetest9, command=google)
button_qwer9.grid(row=3, column=1)
def olx():
if True:
webbrowser.open('https://www.olx.pt/')
else:
return
imagetest10 = PhotoImage(file="olx.png")
button_qwer10 = tk.Button(root, image=imagetest10, command=olx)
button_qwer10.grid(row=3, column=2)
def facebook():
if True:
webbrowser.open('https://www.facebook.com/')
else:
return
imagetest11 = PhotoImage(file="facebook.png")
button_qwer11 = tk.Button(root, image=imagetest11, command=facebook)
button_qwer11.grid(row=3, column=3)
def idealista():
if True:
webbrowser.open('https://www.idealista.pt/comprar-casas/seixal/amora/')
else:
return
imagetest12 = PhotoImage(file="idealista.png")
button_qwer12 = tk.Button(root, image=imagetest12, command=idealista)
button_qwer12.grid(row=3, column=4)
def shutdown():
import subprocess
cmdCommand = "shutdown -s -t 0"
process = subprocess.Popen(cmdCommand.split(), stdout=subprocess.PIPE)
imagetest13 = PhotoImage(file="shutdown.png")
button_qwer13 = tk.Button(root, image=imagetest13, command=shutdown)
button_qwer13.grid(row=5, column=4)
root.mainloop()
def main():
base()
if __name__== ("__main__"):
main() My goal is to add a loading bar. When the user press the button, the bar will get to 100 and then it will open the exe command or the web browser, also, how to apply the bar on the bottom left corner
Tkinter Window Image
Posts: 12,032
Threads: 486
Joined: Sep 2016
Posts: 59
Threads: 9
Joined: Apr 2019
Many thanks for the reply Quote:Larz60
but it doesn't help, because i know it's something similar to ttk.progressbar, but it doesn't explain where to put it and apply to all the buttons. I've searched more then 20 videos and 30 webpages without finding the proper solution. Maybe i have found it, but without knowing where to apply the code. Regards, Francisco
Posts: 59
Threads: 9
Joined: Apr 2019
Apr-08-2019, 12:50 AM
(This post was last modified: Apr-08-2019, 12:50 AM by francisco_neves2020.)
YOU CAN CLICK WHERE IT SAYS IMAGE AND SEE THE PICTURE
This is an image of final project, i just want to add the loading bar when a button is pressed, only proceeding to open the internet browser or the exe file when the bar reached and stopped at 100%.
Posts: 59
Threads: 9
Joined: Apr 2019
Please, the only thing left is just a load bar - i want to add it, i have found thousands of information about ttk.progressbar, but i don't know where to put each part inside the code. Want to add the loading bar at the bottom, when someone press it, the bar loads until 100 and then stop, after that execute the command itself(open word.exe, open browser), if person returns to tkinter window the bar should reset to 0, so it repeat again when another button is pressed.
import os
import sys
import tkinter as tk
from tkinter import *
import subprocess
import idlelib
import urllib.request
import ctypes
import functools
from tkinter import PhotoImage
import webbrowser
from tkinter import messagebox
def base():
def word():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["WINWORD.exe"])
else:
return
imagetest = PhotoImage(file="word.png")
button_qwer = tk.Button(root, image=imagetest, command=word)
button_qwer.grid(row=1, column=1)
def excel():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["EXCEL.exe"])
else:
return
imagetest2 = PhotoImage(file="excel.png")
button_qwer2 = tk.Button(root, image=imagetest2, command=excel)
button_qwer2.grid(row=1, column=2)
def powerpoint():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["POWERPNT.exe"])
else:
return
imagetest3 = PhotoImage(file="powerpoint.png")
button_qwer3 = tk.Button(root, image=imagetest3, command=powerpoint)
button_qwer3.grid(row=1, column=3)
def publisher():
if True:
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["MSPUB.exe"])
else:
return
imagetest4 = PhotoImage(file="publisher.png")
button_qwer4 = tk.Button(root, image=imagetest4, command=publisher)
button_qwer4.grid(row=1, column=4)
def outlook():
if True:
webbrowser.open('https://login.live.com/')
else:
return
imagetest5 = PhotoImage(file="outlook.png")
button_qwer5 = tk.Button(root, image=imagetest5, command=outlook)
button_qwer5.grid(row=2, column=1)
def gmail():
if True:
webbrowser.open('https://accounts.google.com/ServiceLogin/identifier?hl=pt-PT&passive=true&continue=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dgooglw%26ie%3D%26oe%3D&flowName=GlifWebSignIn&flowEntry=AddSession')
else:
return
imagetest6 = PhotoImage(file="gmail.png")
button_qwer6 = tk.Button(root, image=imagetest6, command=gmail)
button_qwer6.grid(row=2, column=2)
def notepad():
if True:
path = "C:/WINDOWS/system32/"
os.chdir(path)
subprocess.run(["notepad.exe"])
else:
return
imagetest7 = PhotoImage(file="notepad.png")
button_qwer7 = tk.Button(root, image=imagetest7, command=notepad)
button_qwer7.grid(row=2, column=3)
def meteorologia():
if True:
webbrowser.open('https://www.google.com/search?q=meteorologia&ie=&oe=')
else:
return
imagetest8 = PhotoImage(file="meteorologia.png")
button_qwer8 = tk.Button(root, image=imagetest8, command=meteorologia)
button_qwer8.grid(row=2, column=4)
def google():
if True:
webbrowser.open('https://www.google.pt/')
else:
return
imagetest9 = PhotoImage(file="google.png")
button_qwer9 = tk.Button(root, image=imagetest9, command=google)
button_qwer9.grid(row=3, column=1)
def olx():
if True:
webbrowser.open('https://www.olx.pt/')
else:
return
imagetest10 = PhotoImage(file="olx.png")
button_qwer10 = tk.Button(root, image=imagetest10, command=olx)
button_qwer10.grid(row=3, column=2)
def facebook():
if True:
webbrowser.open('https://www.facebook.com/')
else:
return
imagetest11 = PhotoImage(file="facebook.png")
button_qwer11 = tk.Button(root, image=imagetest11, command=facebook)
button_qwer11.grid(row=3, column=3)
def idealista():
if True:
webbrowser.open('https://www.idealista.pt/comprar-casas/seixal/amora/')
else:
return
imagetest12 = PhotoImage(file="idealista.png")
button_qwer12 = tk.Button(root, image=imagetest12, command=idealista)
button_qwer12.grid(row=3, column=4)
def shutdown():
import subprocess
cmdCommand = "shutdown -s -t 0"
process = subprocess.Popen(cmdCommand.split(), stdout=subprocess.PIPE)
imagetest13 = PhotoImage(file="shutdown.png")
button_qwer13 = tk.Button(root, image=imagetest13, command=shutdown)
button_qwer13.grid(row=5, column=4)
root.mainloop()
def main():
base()
if __name__== ("__main__"):
main()
Posts: 12,032
Threads: 486
Joined: Sep 2016
Thread merged, don't start new threads on same subject as another
Posts: 59
Threads: 9
Joined: Apr 2019
(Apr-07-2019, 10:28 PM)Larz60+ Wrote: you can do this with ttk.progressbar.
see manual for documentation here: https://www.blog.pythonlibrary.org/2015/...th-python/
and here: https://docs.python.org/3/library/tkinte...rogressbar
and find some examples here:
https://riptutorial.com/tkinter/example/...rogressbar
(Apr-08-2019, 05:34 PM)Larz60+ Wrote: Thread merged, don't start new threads on same subject as another Yes, but can someone help? I read almost everything, i'm not asking to write the full code for each button(just a tip), just for one i do the rest, and not to forget, that python is now version 3.7, most of the older codes don't work
Posts: 12,032
Threads: 486
Joined: Sep 2016
All of the tools needed have been pointed out to you.
You need to make an attempt to write the progress bar code.
When you run into trouble, show us where you are having an issue, and we will be glad to help.
Posts: 59
Threads: 9
Joined: Apr 2019
(Apr-08-2019, 06:10 PM)Larz60+ Wrote: All of the tools needed have been pointed out to you. You need to make an attempt to write the progress bar code. When you run into trouble, show us where you are having an issue, and we will be glad to help. class ProgressBar:
def __init__(self):
self.root = tk.Tk()
self.root.geometry('540x540')
self.root.title(' PROGRAMA PRINCIPAL')
self.step = tk.DoubleVar()
self.progbar1 = ttk.Progressbar
self.progbar2 = ttk.Progressbar
self.progbar3 = ttk.Progressbar
self.frame = tk.Frame()
self.frame.grid()
imagetest = PhotoImage(file="word.png")
button_qwer = tk.Button(image = imagetest, command=self.start_progbar1)
button_qwer.grid(row=1, column=2)
imagetest1 = PhotoImage(file="powerpoint.png")
button_qwer = tk.Button(image = imagetest1, command=self.start_progbar2)
button_qwer.grid(row=1, column=3)
imagetest2 = PhotoImage(file="excel.png")
button_qwer = tk.Button(image = imagetest2, command=self.start_progbar3)
button_qwer.grid(row=1, column=4)
self.root.mainloop()
def start_progbar1(self):
self.progbar1 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar1.grid(columnspan=3)
for x in range(1,120):
self.step.set(x)
time.sleep(0.1)
self.root.update()
self.progbar1.destroy()
if True:
word()
def start_progbar2(self):
self.progbar2 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar2.grid(columnspan=3)
for x in range(1,120):
self.step.set(x)
time.sleep(0.1)
self.root.update()
self.progbar2.destroy()
if True:
powerpoint()
def start_progbar3(self):
if True:
self.progbar3 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar3.grid(columnspan=3)
for x in range(1,120):
self.step.set(x)
time.sleep(0.1)
self.root.update()
self.progbar3.destroy()
if True:
excel()
def word():
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["WINWORD.exe"])
def powerpoint():
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["POWERPNT.exe"])
def excel():
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
subprocess.run(["EXCEL.exe"])
if __name__ == '__main__':
ProgressBar() I have done what you ask, it is working, but the problem i have is i can't place the "loading bar" anywhere else, i tried all the codes, but the ones that allow me to place the bar in the bottom, makes my buttons move to the right when the "loading bar appears" and if i don't use "self.progbar.destroy()",, when i pressed another button, a second, a third bar appears and so on (all of them loading).
Resuming:
move the loading bar to the bottom - without moving the buttons
don't allow another bars to popup, just the same - keep the bar visible at all times
Can you provide assistance for this?
Posts: 5,151
Threads: 396
Joined: Sep 2016
Apr-08-2019, 09:29 PM
(This post was last modified: Apr-08-2019, 09:29 PM by metulburr.)
I havent done tkinter in a long time. So i am very rusty with placement. But you are assinging the same widget to the same cell pushing the buttons to the right. I would explicitly state row and column for each. Such as
imagetest = PhotoImage(file="house.png")
button_qwer = tk.Button(image = imagetest, command=self.start_progbar1)
button_qwer.grid(row=1, column=2)
imagetest1 = PhotoImage(file="house.png")
button_qwer = tk.Button(image = imagetest1, command=self.start_progbar2)
button_qwer.grid(row=1, column=3)
imagetest2 = PhotoImage(file="house.png")
button_qwer = tk.Button(image = imagetest2, command=self.start_progbar3)
button_qwer.grid(row=1, column=4)
self.root.mainloop()
def start_progbar1(self):
self.progbar1 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar1.grid(row=2, column=5)
for x in range(1,120):
self.step.set(x)
time.sleep(0.1)
self.root.update()
self.progbar1.destroy()
if True:
word()
def start_progbar2(self):
self.progbar2 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar2.grid(row=3, column=5)
for x in range(1,120):
self.step.set(x)
time.sleep(0.1)
self.root.update()
self.progbar2.destroy()
if True:
powerpoint()
def start_progbar3(self):
if True:
self.progbar3 = ttk.Progressbar(orient=tk.HORIZONTAL, mode='determinate', variable=self.step)
self.progbar3.grid(row=4, column=5) If you wanted to move it down to the bottom, i would suspect you would put it in a frame (just the progressbars and not the buttons) and assign that to the bottom. You can assign empty frames to use as a spacer to get to the bottom until your actually put something in the middle. (if i recall correctly). I would also split up your class. Because buttons are not progressbars and hence if you want to the move the class to the bottom, you would then be moving the buttons as well.
Recommended Tutorials:
|