0
884views
Write a python program which displays a message on clicking a button.
1 Answer
0
64views

Explanation:-

  • Create a onclick function which is called when ever a user clicks on the designed button.
  • Use a tkinter button module to design a button in the root window and in the command argument pass on the name of the function.
  • On clicking a button message would be displayed on the new window.

Code:-

import tkinter.messagebox
from tkinter import *

def onClick():
    root = Tk()
    w = Label(root, text='Welcome to python programming')
    w.pack()

root = tkinter.Tk()
button = tkinter.Button(root,text = "Click Me", command = onClick)
button.pack()
root.mainloop()

Output:-

Root Window

enter image description here

Message Window

enter image description here

Please log in to add an answer.