0% found this document useful (0 votes)
0 views

gui syntax

Uploaded by

nobita.vahith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

gui syntax

Uploaded by

nobita.vahith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

'''

#syntax

import tkinter as tk #alias name(tk)


root=tk.Tk()
"""
statements
"""
root.mainloop()

#*********************************

import tkinter as tk #alias name(tk)


root=tk.Tk()
root.title('GUI Demo Window')
root.geometry('1000x1000') #LxB
root.mainloop()

#*********************************

from tkinter import *


root=Tk()
root.title('GUI Demo Window')
root.geometry('300x200') #LxB
label=Label(root,text="Hello")
label.pack()
root.mainloop()

#pack = place the text automatically center


#place = place the text in given position

#*********************************
from tkinter import *
root=Tk()
root.title('GUI Demo Window')
root.geometry('300x200') #LxB
label=Label(root,text="Hello",font=("arial","20","italic",'bold'))
label.pack()
root.mainloop()

#pack = place the text automatically center


#place = place the text in given position

#*********************************

from tkinter import *


root=Tk()
root.title('GUI Demo Window')
root.geometry('300x200') #LxB
label=Label(root,text="Hello",font=("arial","20","bold"),bg="black",fg='yellow')
label.pack()
bt=Button(root,text="click1",font=('elephant',"18",'bold'),bg='red',fg='cyan',
relief='solid')
bt.pack()
bt1=Button(root,text="click2",font=('elephant',"18",'bold'),bg='red',fg='cyan',
relief='ridge')
bt1.pack()
bt2=Button(root,text="click3",font=('elephant',"18",'bold'),bg='red',fg='cyan',
relief='groove')
bt2.pack()
bt3=Button(root,text="click4",font=('elephant',"18",'bold'),bg='red',fg='cyan',
relief='raised')
bt3.pack()
root.mainloop()

'''
#*********************************

#my gui
from tkinter import *
import tkinter as tk
from tkinter import messagebox

window=Tk()
window.title("Text Box example")
window.geometry("300x400")

#label
label=Label(window,text="Name:",font=("arial",20),fg="black",bg="pink")
label.grid(column = 0, row = 0)

def click():
messagebox.showinfo(name.get())

def changelabel():
label.config(text=name.get())

def optionselection():
messagebox.showinfo("message","you have selected a "+choice.get())
def listselection():
str1=listbox.curselection()
messagebox.showinfo("Message","you have selected a"+
listbox.get(listbox.curselection()))

#entry
name= tk.StringVar()
text=Entry(window,width =20 , textvariable = name)
text.grid(column = 1, row = 0)

#button
btn=Button(window,text="Click me", bg="orange", command=listselection)
btn.grid(row = 1, column = 1)

#radio button
choice=tk.StringVar()
rd1=Radiobutton(window,text="Fruits", variable=choice, value="fruits",
command=optionselection)
rd1.grid(row=2,column=0)

rd2=Radiobutton(window,text="Vegetables", variable=choice, value="vegetable",


command=optionselection)
rd2.grid(row=3,column=0)
rd3=Radiobutton(window,text="Cosmetics", variable=choice, value="Cosmetics",
command=optionselection)
rd3.grid(row=4,column=0)

#listbox
listbox=Listbox(window,selectmode=tk.SINGLE)
listbox.grid(row=5,column=1)
listbox.insert(1,"fruits")
listbox.insert(2,"veg")
listbox.insert(3,"cosmetics")
window.mainloop()

#*********************************
'''
#Simple menu
from tkinter import *

top = Tk()

def hello():
print("hello!")

# create a toplevel menu


menubar = Menu(top)
menubar.add_command(label="Hello!", command=hello)
menubar.add_command(label="Quit!", command=top.quit)

# display the menu


top.config(menu=menubar)

top.mainloop()

'''

You might also like