Here we are going to write a code in python about pass argument to tkinter button. In output we get one button after clicking that button we can get some text which we given in that code.
these code will be easy and very simple to understand
Algorithm
- At first import a necessary library: Tkinter
- create a main window (root)
- set the window title to” Scode Network” and geometry to 600×400 pixels
- define a function to display a label (hello)
- Create button with label “Click me” and command hello.
Add button to main window. - create a new label widget with text “welcome”
- use the pack() method to add the label to the window
- create a button widget
- set the button text to “click me”
- set the command parameter to hello function
- add the button to the window using pack()
start the main event loop ( mainloop)
Source code
from tkinter import* root = Tk() root.title ("Scode Network") root.geometry("800x600") def hello(): Label(text="my name is ajay").pack() Button(root,text="click me",command=hello).pack() root.mainloop()
output
welcome