Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] switching frames
#1
I want to switch between two frames instead of creating a new window.I just want to stay in same window and after some button is pressed then the another frame is to be switched.I tried some code but i am getting some error can somebody help me to fix or edit the code

from tkinter import *

def raise_frame(frame):
    frame.tkraise()


root1 = Tk()
root1.geometry('500x500')
root1.title("Registration Form")
root = Frame(root1).pack()
f2 = Frame(root1).pack()

label_0 = Label(root, text="Registration form",width=20,font=("bold", 20))
label_0.place(x=90,y=53)


label_1 = Label(root, text="FullName",width=20,font=("bold", 10))
label_1.place(x=80,y=130)

entry_1 = Entry(root)
entry_1.place(x=240,y=130)

label_2 = Label(root, text="Email",width=20,font=("bold", 10))
label_2.place(x=68,y=180)

entry_2 = Entry(root)
entry_2.place(x=240,y=180)

label_3 = Label(root, text="Gender",width=20,font=("bold", 10))
label_3.place(x=70,y=230)
var = IntVar()
Radiobutton(root, text="Male",padx = 5, variable=var, value=1).place(x=235,y=230)
Radiobutton(root, text="Female",padx = 20, variable=var, value=2).place(x=290,y=230)

label_4 = Label(root, text="country",width=20,font=("bold", 10))
label_4.place(x=70,y=280)

list1 = ['Canada','India','UK','Nepal','Iceland','South Africa'];
c=StringVar()
droplist=OptionMenu(root,c, *list1)
droplist.config(width=15)
c.set('select your country') 
droplist.place(x=240,y=280)

label_4 = Label(root, text="Programming",width=20,font=("bold", 10))
label_4.place(x=85,y=330)
var1 = IntVar()
Checkbutton(root, text="java", variable=var1).place(x=235,y=330)
var2 = IntVar()
Checkbutton(root, text="python", variable=var2).place(x=290,y=330)

Button(root, text='Submit',width=20,bg='brown',fg='white', command=lambda:raise_frame(f2)).place(x=180,y=380)
label_8 = Label(f2, text="Welcome to page 2",width=20,font=("bold", 10))
label_8.place(x=70,y=230)

root1.mainloop()
what should i write to change to frame 2 if the button is pressed in first frame
Larz60+ wrote Apr-16-2019, 03:32 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Hi nick123

Try out following modified script:
from tkinter import *
from functools import partial
 
def raise_frame(frame):
    frame.tkraise()
 
main_win = Tk()
main_win.geometry('500x500')
main_win.title("Registration Form")

second_frame = Frame(main_win)
second_frame.place(x=0, y=0, width=500, height=500)

first_frame = Frame(main_win)
first_frame.place(x=0, y=0, width=500, height=500)


label_0 = Label(first_frame, text="Registration form",width=20,font=("bold", 20))
label_0.place(x=90,y=53)
 
 
label_1 = Label(first_frame, text="FullName",width=20,font=("bold", 10))
label_1.place(x=80,y=130)
 
entry_1 = Entry(first_frame)
entry_1.place(x=240,y=130)
 
label_2 = Label(first_frame, text="Email",width=20,font=("bold", 10))
label_2.place(x=68,y=180)
 
entry_2 = Entry(first_frame)
entry_2.place(x=240,y=180)
 
label_3 = Label(first_frame, text="Gender",width=20,font=("bold", 10))
label_3.place(x=70,y=230)
var = IntVar()
Radiobutton(first_frame, text="Male",padx = 5, variable=var, value=1).place(x=235,y=230)
Radiobutton(first_frame, text="Female",padx = 20, variable=var, value=2).place(x=290,y=230)
 
label_4 = Label(first_frame, text="country",width=20,font=("bold", 10))
label_4.place(x=70,y=280)
 
list1 = ['Canada','India','UK','Nepal','Iceland','South Africa'];
c=StringVar()
droplist=OptionMenu(first_frame,c, *list1)
droplist.config(width=15)
c.set('select your country') 
droplist.place(x=240,y=280)
 
label_4 = Label(first_frame, text="Programming",width=20,font=("bold", 10))
label_4.place(x=85,y=330)
var1 = IntVar()
Checkbutton(first_frame, text="java", variable=var1).place(x=235,y=330)
var2 = IntVar()
Checkbutton(first_frame, text="python", variable=var2).place(x=290,y=330)
 
Button(first_frame, text='Submit',width=20,bg='brown',fg='white', command=lambda:raise_frame(second_frame)).place(x=180,y=380)

label_8 = Label(second_frame, text="Welcome to page 2",width=20,font=("bold", 10))
label_8.place(x=70,y=230)

Button(second_frame, text="Switch back to page 1",width=20,bg='brown',fg='white', command=lambda:raise_frame(first_frame)).place(x=180,y=380) 

main_win.mainloop()
wuf :-)
Quote
#3
(Apr-16-2019, 07:30 PM)wuf Wrote: Hi nick123

Try out following modified script:
from tkinter import *
from functools import partial
 
def raise_frame(frame):
    frame.tkraise()
 
main_win = Tk()
main_win.geometry('500x500')
main_win.title("Registration Form")

second_frame = Frame(main_win)
second_frame.place(x=0, y=0, width=500, height=500)

first_frame = Frame(main_win)
first_frame.place(x=0, y=0, width=500, height=500)


label_0 = Label(first_frame, text="Registration form",width=20,font=("bold", 20))
label_0.place(x=90,y=53)
 
 
label_1 = Label(first_frame, text="FullName",width=20,font=("bold", 10))
label_1.place(x=80,y=130)
 
entry_1 = Entry(first_frame)
entry_1.place(x=240,y=130)
 
label_2 = Label(first_frame, text="Email",width=20,font=("bold", 10))
label_2.place(x=68,y=180)
 
entry_2 = Entry(first_frame)
entry_2.place(x=240,y=180)
 
label_3 = Label(first_frame, text="Gender",width=20,font=("bold", 10))
label_3.place(x=70,y=230)
var = IntVar()
Radiobutton(first_frame, text="Male",padx = 5, variable=var, value=1).place(x=235,y=230)
Radiobutton(first_frame, text="Female",padx = 20, variable=var, value=2).place(x=290,y=230)
 
label_4 = Label(first_frame, text="country",width=20,font=("bold", 10))
label_4.place(x=70,y=280)
 
list1 = ['Canada','India','UK','Nepal','Iceland','South Africa'];
c=StringVar()
droplist=OptionMenu(first_frame,c, *list1)
droplist.config(width=15)
c.set('select your country') 
droplist.place(x=240,y=280)
 
label_4 = Label(first_frame, text="Programming",width=20,font=("bold", 10))
label_4.place(x=85,y=330)
var1 = IntVar()
Checkbutton(first_frame, text="java", variable=var1).place(x=235,y=330)
var2 = IntVar()
Checkbutton(first_frame, text="python", variable=var2).place(x=290,y=330)
 
Button(first_frame, text='Submit',width=20,bg='brown',fg='white', command=lambda:raise_frame(second_frame)).place(x=180,y=380)

label_8 = Label(second_frame, text="Welcome to page 2",width=20,font=("bold", 10))
label_8.place(x=70,y=230)

Button(second_frame, text="Switch back to page 1",width=20,bg='brown',fg='white', command=lambda:raise_frame(first_frame)).place(x=180,y=380) 

main_win.mainloop()
wuf :-)
Hi wuf, i'm working on this code also, much more complex with more features, my main question is, how can anyone, after fulfill all the questions send to an specific email after the submitted button is pressed? I've tried several codes on searches i have made, but none works, it reports errors, like SMTP doesn't have this or that. Probably those codes don't work on the newest version of python, can you provide assitance on this matter, regards, Francisco.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Unable to Access global Variable when switching between frames tziyong 1 138 Nov-03-2019, 01:08 AM
Last Post: balenaucigasa
  [Tkinter] Call a function when switching layouts 4096 0 1,328 Sep-22-2019, 07:39 PM
Last Post: 4096
  [PyGUI] Switching between two frames using Tkinter jenkins43 1 268 Jul-17-2019, 10:53 AM
Last Post: metulburr
  Problem with pygame not switching the mouse image Mondaythe1st 6 2,245 Jul-26-2017, 10:53 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)