dropdown menu

Back To Home

Friday, December 20, 2019

python tkinter-update label while program running (progress bar from 0% to 100%)

python tkinter update label while program running (progress bar from 0% to 100%)
Update continuously even you have button and button is clicked.
Just put config text and root.update() inside function def.

The progress bar:


Program:

from tkinter import *
import time

root=Tk()

a=Label(root,fg="blue")
a.pack()

a.config(text="processing 10%")
root.update()
time.sleep(1)
#program
a.config(text="processing 30%")
root.update()
time.sleep(1)
#program
a.config(text="processing 60%")
root.update()
time.sleep(1)
#program
a.config(text="processing 100%")
root.update()
time.sleep(1)

root.mainloop()



Python tkinter update label progress bar while button is clicked.

The progress bar(with button):


Program:
from tkinter import *
import time

root=Tk()

a=Label(root,fg="blue")
a.pack()

def run():
 a.config(text="processing 10%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 30%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 60%")
 root.update()
 time.sleep(1)
 #program
 a.config(text="processing 100%")
 root.update()
 time.sleep(1)

b=Button(root,text="run",command=run)
b.pack()



root.mainloop()

                  

Sunday, December 8, 2019

Python tkinter- Screen1 appear on top or bottom screen 2

Python code:

Page1.py:

import tkinter as tk
import os

root = tk.Tk()
root.attributes('-type', 'dock')
root.title('top')
#root.attributes('-type', 'splash')
root.geometry('200x200+100+100')

def open():
  os.system('python3 top2')
  
a=tk.Button(root,text="open screen 2",command=open)
a.pack()

root.mainloop()

Page2.py:

import tkinter as tk

root = tk.Tk()

root.title('top2')

root.geometry('200x200+150+150')
root.mainloop()


Screen 2 appear on top screen 1(dock):




Screen 2 appear on bottom screen 1(splash):

Video: