1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import Tkinter as tk counter = 0 def counter_label(lable): counter = 0 def count(): global counter counter + = 1 label.config(text = str (counter)) label.after( 1000 ,count) count() root = tk.Tk() root.title( "Counting Seconds" ) label = tk.Label(root, fg = "dark green" ) label.pack() counter_label(label) button = tk.Button(root, text = "Stop" , width = 25 , command = root.destroy) button.pack() root.mainloop() |
1 2 3 4 5 6 7 8 9 10 | import Tkinter import tkMessageBox top = Tkinter.Tk() def helloCallBack(): tkMessageBox.showinfo( "hello Python" , "Hello word" ) B = Tkinter.Button(top,text = "Hello button" ,command = helloCallBack) B.pack() top.mainloop(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from tkinter import * from tkinter import messagebox top = Tk() top.geometry( "300x200" ) top.title( 'Hello Python' ) def red(): messagebox.showerror( "Hello" , "Red Button clicked" ) def blue(): messagebox.showinfo( "Hello" , "Blue Button clicked" ) def green(): messagebox.showinfo( "Hello" , "Green Button clicked" ) def clicked(): res = "Welcome to " + txt.get() lbl.configure(text = res) b1 = Button(top,text = "Red" ,command = red,activeforeground = "red" ,activebackground = "pink" ,bg = "green" ,font = "14" ,pady = 10 ) b2 = Button(top, text = "Blue" ,command = blue,activeforeground = "blue" ,activebackground = "pink" ,pady = 10 ) b3 = Button(top, text = "Green" ,command = green,activeforeground = "green" ,activebackground = "pink" ,pady = 10 ) b4 = Button(top, text = "Yellow" ,command = clicked,activeforeground = "yellow" ,activebackground = "pink" ,pady = 10 ) lbl = Label(top,text = "Hello" ,font = "14" ) txt = Entry(top,width = 50 ) b1.pack(side = LEFT) b2.pack(side = RIGHT) b3.pack(side = TOP) b4.pack(side = BOTTOM) lbl.pack() txt.pack(side = TOP) top.mainloop() |