python 3.x - How to create a sub frames with a specific layout? -
i'm aiming make login program part confuses me how make frames.i need 3 different frames neither know how make frame other this:
mainframe = ttk.frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(n, w, e, s)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1)
and can make labels , widgets using single mainframe. far making one, beyond me. need know place widets inside of each frame , after creating frames don't know how place stuff on grid. go overall grid, or change after making grid. i'm using following layout making frame. i'm hoping crash course in frames. information i've gathered doesn't make sense me, after tried put code.
i've got coding part down not frame part.
#import tkinter make gui tkinter import * tkinter import ttk import codecs def login(*args ): file = open("rot13.txt", "r") lines = file.readlines() uname = user.get() pword = pw.get() in lines: x = i.split() if codecs.encode(uname,'rot13') == x[0] , codecs.encode(pword,'rot13') == x[1]: result.set("successful") break; else: result.set("access denied") root = tk() root.title("login") #configures column , row settings , sets padding mainframe = ttk.frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(n, w, e, s)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) user = stringvar() pw = stringvar() result = stringvar() user_entry = ttk.entry(mainframe, width=20, textvariable=user) user_entry.grid(column=2, row=1, sticky=(w, e)) pw_entry = ttk.entry(mainframe, width=20, textvariable=pw) pw_entry.grid(column=2, row=2, sticky=(w, e)) ttk.label(mainframe, text="username ").grid(column=1, row=1, sticky=w) ttk.label(mainframe, text="password ").grid(column=1, row=2, sticky=w) ttk.label(mainframe, text="").grid(column=1, row=3, sticky=w) ttk.label(mainframe, text="result").grid(column=1, row=4, sticky=w) ttk.label(mainframe, text="").grid(column=1, row=5, sticky=w) ttk.button(mainframe, text="login", command=login).grid(column=3, row=6, sticky=w) #makes spot put in result ttk.label(mainframe, textvariable=result).grid(column=2, row=4, sticky=(w, e)) #opens item selected , allows enter username without having click user_entry.focus() #runs calculate if click enter root.bind('<return>', login) root.mainloop()
i believe key point missing subframes of mainframe use mainframe parent , widgets within subframes use subframe parent. furthermore, can place subframe within mainframe , subframe widgets within subframe. not have pass parents .grid because each widget knows parent. simplified example:
from tkinter import * root = tk() mainframe = frame(root) login = frame(mainframe) label = label(login, text='label') entry = entry(login) display = frame(mainframe) result = label(display, text='display result') mainframe.grid() # within root login.grid(row=0, column=0) # within mainframe label.grid(row=0, column=0) # within login entry.grid(row=0, column=1) # within login display.grid() # within mainfram result.grid(row=2, column=0) # within display
Comments
Post a Comment