from tkinter import *
from tkinter.ttk import *
from time import strftime
# creating tkinter window
my_window = Tk()
my_window.geometry('500x300')
my_window.title('Menu操作')
# Creating Menubar
menubar = Menu(my_window)
# Adding File Menu and commands
filemenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='New File', command=None)
filemenu.add_command(label='Open...', command=None)
filemenu.add_command(label='Save', command=None)
filemenu.add_separator()
filemenu.add_command(label='Exit', command=my_window.destroy)
# Adding Edit Menu and commands
editmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Edit', menu=editmenu)
editmenu.add_command(label='Cut', command=None)
editmenu.add_command(label='Copy', command=None)
editmenu.add_command(label='Paste', command=None)
editmenu.add_command(label='Select All', command=None)
editmenu.add_separator()
editmenu.add_command(label='Find...', command=None)
editmenu.add_command(label='Find again', command=None)
# Adding Help Menu
helpmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='Tk Help', command=None)
helpmenu.add_command(label='Demo', command=None)
helpmenu.add_separator()
helpmenu.add_command(label='About Tk', command=None)
# display Menu
my_window.config(menu=menubar)
# This function is used to
# display time on the label
def time():
string = strftime('%H:%M:%S %p')
label_1.config(text=string)
label_1.after(1000, time)
# Styling the label widget so that clock
# will look more attractive
label_1 = Label(my_window,font=('calibri', 40, 'bold'),background='purple',foreground='white')
# Placing clock at the centre
# of the tkinter window
label_1.pack(anchor='center')
time()
my_window.mainloop()
from tkinter.ttk import *
from time import strftime
# creating tkinter window
my_window = Tk()
my_window.geometry('500x300')
my_window.title('Menu操作')
# Creating Menubar
menubar = Menu(my_window)
# Adding File Menu and commands
filemenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='New File', command=None)
filemenu.add_command(label='Open...', command=None)
filemenu.add_command(label='Save', command=None)
filemenu.add_separator()
filemenu.add_command(label='Exit', command=my_window.destroy)
# Adding Edit Menu and commands
editmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Edit', menu=editmenu)
editmenu.add_command(label='Cut', command=None)
editmenu.add_command(label='Copy', command=None)
editmenu.add_command(label='Paste', command=None)
editmenu.add_command(label='Select All', command=None)
editmenu.add_separator()
editmenu.add_command(label='Find...', command=None)
editmenu.add_command(label='Find again', command=None)
# Adding Help Menu
helpmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='Tk Help', command=None)
helpmenu.add_command(label='Demo', command=None)
helpmenu.add_separator()
helpmenu.add_command(label='About Tk', command=None)
# display Menu
my_window.config(menu=menubar)
# This function is used to
# display time on the label
def time():
string = strftime('%H:%M:%S %p')
label_1.config(text=string)
label_1.after(1000, time)
# Styling the label widget so that clock
# will look more attractive
label_1 = Label(my_window,font=('calibri', 40, 'bold'),background='purple',foreground='white')
# Placing clock at the centre
# of the tkinter window
label_1.pack(anchor='center')
time()
my_window.mainloop()
评论
发表评论