0% found this document useful (0 votes)
64 views6 pages

Tkinter Menu Interface Guide

The document describes code for creating a GUI interface with menus and a text box widget. It defines a class called mywidgets that contains methods for creating the menu bar, text box, and opening files. The makeMenuBar method builds the menu bar with options for File, Edit, View, Insert, Format, Tools, and Help. It also includes a file_open method to open and print the selected file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views6 pages

Tkinter Menu Interface Guide

The document describes code for creating a GUI interface with menus and a text box widget. It defines a class called mywidgets that contains methods for creating the menu bar, text box, and opening files. The makeMenuBar method builds the menu bar with options for File, Edit, View, Insert, Format, Tools, and Help. It also includes a file_open method to open and print the selected file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

Jairo Yumbla Romero, Esteban Sánchez Dután

EJERCICIO 1

from Tkinter import *

from tkFileDialog import askopenfilename

class mywidgets:

def __init__(self,root):

frame=Frame(root)

self.makeMenuBar(frame)

self.txtfr(frame)

frame.pack()

return

def txtfr(self,frame):

textfr = Frame(frame)

self.text = Text(textfr,height = 10,width = 50,background='white')

scroll = Scrollbar(textfr)

self.text.configure(yscrollcommand = scroll.set)

self.text.pack(side = LEFT)

scroll.pack(side = RIGHT,fill = Y)

textfr.pack(side = TOP)

return

def makeMenuBar(self,frame):

menubar = Frame(frame,relief = RAISED,borderwidth = 1)


menubar.pack()

mb_file = Menubutton(menubar,text = 'archivo')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'abrir',command = self.file_open)

mb_file.menu.add_command(label = 'cerrar',command = self.file_open)

mb_file['menu'] = mb_file.menu

mb_edit = Menubutton(menubar,text = 'edicion')

mb_edit.pack(side = LEFT)

mb_edit.menu = Menu(mb_edit)

mb_edit.menu.add_command(label = 'copy')

mb_edit.menu.add_command(label = 'pegar')

mb_file = Menubutton(menubar,text = 'ver')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'total',command = self.file_open)

mb_file.menu.add_command(label = 'normal',command = self.file_open)

mb_file['menu'] = mb_file.menu

mb_edit['menu'] = mb_edit.menu

mb_file = Menubutton(menubar,text = 'insertar')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'nuevo',command = self.file_open)

mb_file.menu.add_command(label = 'audio',command = self.file_open)

mb_file['menu'] = mb_file.menu

mb_file = Menubutton(menubar,text = 'formato')


mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'fuente',command = self.file_open)

mb_file.menu.add_command(label = 'parrrafo',command = self.file_open)

mb_file['menu'] = mb_file.menu

mb_file = Menubutton(menubar,text = 'herramienta')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'ortografia',command = self.file_open)

mb_file.menu.add_command(label = 'idioma',command = self.file_open)

mb_file['menu'] = mb_file.menu

mb_file = Menubutton(menubar,text = 'ayuda')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'F1',command = self.file_open)

mb_file.menu.add_command(label = 'actualizaciones',command = self.file_open)

mb_file['menu'] = mb_file.menu

return

def file_open(self):

root = Tk()

filename =askopenfilename(filetypes=[("allfiles","*"),("pythonfiles","*.py")])

print filename
def main():

root = Tk()

k = mywidgets(root)

root.title('MENU')

root.mainloop()

main()

-----------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------

EJERCICIO 2

from Tkinter import *

from tkFileDialog import askopenfilename

class mywidgets:

def __init__(self,root):

frame=Frame(root)

self.makeMenuBar(frame)

self.txtfr(frame)

frame.pack()

return

def txtfr(self,frame):

textfr = Frame(frame)

self.text = Text(textfr,height = 20,width = 50,background='white')

scroll = Scrollbar(textfr)

self.text.configure(yscrollcommand = scroll.set)

self.text.pack(side = LEFT)
scroll.pack(side = RIGHT,fill = Y)

textfr.pack(side = TOP)

return

def makeMenuBar(self,frame):

menubar = Frame(frame,relief = RAISED,borderwidth = 1)

menubar.pack()

mb_file = Menubutton(menubar,text = 'Archivo')

mb_file.pack(side = LEFT)

mb_file.menu = Menu(mb_file)

mb_file.menu.add_command(label = 'open',command = self.file_open)

mb_edit = Menubutton(menubar,text = 'edit')

mb_edit.menu = Menu(mb_edit)

mb_edit.menu.add_command(label = 'copy')

mb_help = Menubutton(menubar,text = 'help')

mb_file['menu'] = mb_file.menu

mb_edit['menu'] = mb_edit.menu

return

def file_open(self):

root = Tk()

filename2 =askopenfilename(filetypes=[("allfiles","*"),("pythonfiles","*.docx"),
("pythonfiles","*.jpg"),("pythonfiles","*.docx"),("pythonfiles","*.xlsx"),("pythonfiles","*.pptx")])
print filename2

def main():

root = Tk()

k = mywidgets(root)

root.title('interface')

root.mainloop()

main()

You might also like