Python3.5 tkinter implements page Jump and python3.5tkinter
This article provides an example of how tkinter implements page Jump for your reference. The specific content is as follows:
Main function main. py
From tkinter import * from LoginPage import * root = Tk () root. title ('applet ') LoginPage (root) root. mainloop ()
LoginPage. py
From tkinter import * from tkinter. messagebox import * from MainPage import * class LoginPage (object): def _ init _ (self, master = None): self. root = master # define the internal variable root self. root. geometry ('% dx % d' % (300,180) # Set the window size self. username = StringVar () self. password = StringVar () self. createPage () def createPage (self): self. page = Frame (self. root) # create Frame self. page. pack () Label (self. page ). grid (row = 0, stick = W) Label (self. page, text = 'account :'). grid (row = 1, stick = W, pady = 10) Entry (self. page, textvariable = self. username ). grid (row = 1, column = 1, stick = E) Label (self. page, text = 'password :'). grid (row = 2, stick = W, pady = 10) Entry (self. page, textvariable = self. password, show = '*'). grid (row = 2, column = 1, stick = E) Button (self. page, text = 'login', command = self. loginCheck ). grid (row = 3, stick = W, pady = 10) Button (self. page, text = 'exit ', Command = self. page. quit ). grid (row = 3, column = 1, stick = E) def loginCheck (self): name = self. username. get () secret = self. password. get () if name = 'hangzhou' and secret = '000000': self. page. destroy () MainPage (self. root) else: showinfo (title = 'error', message = 'wrong account or password! ')
Main interface function MainPage. py
From tkinter import * from view import * # Main Page (object): def _ init _ (self, master = None): self. root = master # define the internal variable root self. root. geometry ('% dx % d' % (600,400) # Set the window size self. createPage () def createPage (self): self. inputPage = InputFrame (self. root) # create different frames self. queryPage = QueryFrame (self. root) self. countPage = CountFrame (self. root) self. aboutPage = AboutFrame (self. root) self. inputPage. pack () # menubar = Menu (self. root) menubar. add_command (label = 'Data Input ', command = self. inputData) menubar. add_command (label = 'query', command = self. queryData) menubar. add_command (label = 'statistics', command = self. countData) menubar. add_command (label = 'about ', command = self. aboutDisp) self. root ['menu '] = menubar # Set the menu bar def inputData (self): self. inputPage. pack () self. queryPage. pack_forget () self. countPage. pack_forget () self. aboutPage. pack_forget () def queryData (self): self. inputPage. pack_forget () self. queryPage. pack () self. countPage. pack_forget () self. aboutPage. pack_forget () def countData (self): self. inputPage. pack_forget () self. queryPage. pack_forget () self. countPage. pack () self. aboutPage. pack_forget () def aboutDisp (self): self. inputPage. pack_forget () self. queryPage. pack_forget () self. countPage. pack_forget () self. aboutPage. pack ()
Sub-interface function view, py
From tkinter import * from tkinter. messagebox import * class InputFrame (Frame): # inherit the Frame class def _ init _ (self, master = None): Frame. _ init _ (self, master) self. root = master # define the internal variable root self. itemName = StringVar () self. importPrice = StringVar () self. sellPrice = StringVar () self. deductPrice = StringVar () self. createPage () def createPage (self): Label (self ). grid (row = 0, stick = W, pady = 10) Label (self, text = 'drug name :'). grid (row = 1, stick = W, pady = 10) Entry (self, textvariable = self. itemName ). grid (row = 1, column = 1, stick = E) Label (self, text = 'price/RMB :'). grid (row = 2, stick = W, pady = 10) Entry (self, textvariable = self. importPrice ). grid (row = 2, column = 1, stick = E) Label (self, text = 'price/RMB :'). grid (row = 3, stick = W, pady = 10) Entry (self, textvariable = self. sellPrice ). grid (row = 3, column = 1, stick = E) Label (self, text = 'discount/RMB :'). grid (row = 4, stick = W, pady = 10) Entry (self, textvariable = self. deductPrice ). grid (row = 4, column = 1, stick = E) Button (self, text = 'input '). grid (row = 6, column = 1, stick = E, pady = 10) class QueryFrame (Frame): # inherit the Frame class def _ init _ (self, master = None): Frame. _ init _ (self, master) self. root = master # define the internal variable root self. itemName = StringVar () self. createPage () def createPage (self): Label (self, text = 'query interface '). pack () class CountFrame (Frame): # inherit the Frame class def _ init _ (self, master = None): Frame. _ init _ (self, master) self. root = master # define the internal variable root self. createPage () def createPage (self): Label (self, text = 'statistical interface '). pack () class AboutFrame (Frame): # inherit the Frame class def _ init _ (self, master = None): Frame. _ init _ (self, master) self. root = master # define the internal variable root self. createPage () def createPage (self): Label (self, text = 'about interface '). pack ()
:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.