Συζήτηση
Γεια χαρά, Επισκέπτης
Όνομα χρήστη: Κωδικός: Να με θυμάσαι

ΘΕΜΑ: Δημιουργία Command Button σε TkInter για να αλλάζω frame

Δημιουργία Command Button σε TkInter για να αλλάζω frame 12 Χρόνια 5 Μήνες πριν #1559

  • STRATOS
  • Το Άβαταρ του/της STRATOS
  • Αποσυνδεμένος
  • pyt___
  • Δημοσιεύσεις: 34
  • Ληφθείσες Ευχαριστίες 5
Έχω δημιουργήσει το παρακάτω interface για login(form1) σε Visual Python TkInter Idle και θέλω πατώντας το button να μου εμφανίζει στο ίδιο παράθυρο μια form2 που έχω φτιάξει.Μπορεί κάποιος να μου πέις πώς θα το κανω αυτό?

form1
#	Project Name	:	Visual Python IDE for 2.6
#	Date	        :	13-12-2009
#	Author		    :	macrocoders team
#	Contact		    :	macrocoders@gmail.com
#	Web			    :	http://visualpython.org
#	Python Ver.     :	2.6
 
# -*- coding: utf-8 -*-
 
from Tkinter import *
from tkMessageBox import *
from form_py import *
 
# -- Do not change. You may experience problems with the design file. #
form1=Tk()
form1.title('form1')
form1.resizable(width=FALSE, height=FALSE)
form1.geometry('262x191+100+100')
# -- Do not change. You may experience problems with the design file. #
 
# -- Do not change. You may experience problems with the design file. -- #
textBox2=Entry(font = '{MS Sans Serif} 10',show='*')
textBox2.place(relx=0.57, rely=0.26, relwidth=0.38, relheight=0.10)
 
# -- Do not change. You may experience problems with the design file. -- #
textBox1=Entry(font = '{MS Sans Serif} 10')
textBox1.place(relx=0.57, rely=0.07, relwidth=0.38, relheight=0.10)
 
# -- Do not change. You may experience problems with the design file. -- #
label2=Label(text='Κωδικος Χρήστη')
label2.place(relx=0.02, rely=0.26, relwidth=0.41, relheight=0.12)
 
# -- Do not change. You may experience problems with the design file. -- #
label1=Label(text='Όνομα Χρήστη')
label1.place(relx=0.02, rely=0.07, relwidth=0.41, relheight=0.09)
 
# -- Do not change. You may experience problems with the design file. -- #
button1=Button(text='Είσοδος', command=button1Click)
button1.place(relx=0.04, rely=0.59, relwidth=0.88, relheight=0.26)
 
form1.mainloop()

Κώδικας Button
#	Project Name	:	Visual Python IDE for 2.6
#	Date	        :	13-12-2009
#	Author		    :	macrocoders team
#	Contact		    :	macrocoders@gmail.com
#	Web			    :	http://visualpython.org
#	Python Ver.     :	2.6
 
# -*- coding: utf-8 -*-
 
from Tkinter import *
from tkMessageBox import *
 
 
# -- Do not change. You may experience problems with the design file. -- #
def button1Click():
   pass
 
 
#Do not change spaces! description page is here#
Τελευταία διόρθωση: 12 Χρόνια 5 Μήνες πριν από STRATOS.
Πρέπει να είστε εγγεγραμμένο μέλος του Φόρουμ για να κάνετε μια δημοσίευση.

Απ: Δημιουργία Command Button σε TkInter για να αλλάζω frame 12 Χρόνια 5 Μήνες πριν #1560

  • STRATOS
  • Το Άβαταρ του/της STRATOS
  • Αποσυνδεμένος
  • pyt___
  • Δημοσιεύσεις: 34
  • Ληφθείσες Ευχαριστίες 5
Τελικά βρήκα ακριβώς αυτό που ήθελα μετά απο πολύ ψάξιμο ο κώδικας είναι παρακάτω με αρκετες αλλαγές απο τον αρχικό:
# -*- coding: utf8 -*-
import Tkinter as tk
from Tkinter import *
import tkMessageBox
 
 
 
TITLE_FONT = ("Helvetica", 50, "bold")
class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
 
        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
 
        self.frames = {}
        for F in (StartPage, PageOne):
            frame = F(container, self)
            self.frames[F] = frame
            # put all of the pages in the same location; 
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")
 
        self.show_frame(StartPage)
 
    def show_frame(self, c):
        '''Show a frame for the given class'''
        frame = self.frames[c]
        frame.tkraise()
 
class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent) 
        # -- Do not change. You may experience problems with the design file. -- #
        textBox2=tk.Entry(self,font = '{MS Sans Serif} 11',show='*')
        textBox2.place(relx=0.57, rely=0.40, relwidth=0.20, relheight=0.20)
 
        # -- Do not change. You may experience problems with the design file. -- #
        textBox1=tk.Entry(self,font = '{MS Sans Serif} 11')
        textBox1.place(relx=0.57, rely=0.07, relwidth=0.20, relheight=0.20)
 
        # -- Do not change. You may experience problems with the design file. -- #
        label2=tk.Label(self,text='Κωδικος Χρήστη')
        label2.place(relx=0.02, rely=0.40, relwidth=0.41, relheight=0.09)
 
        # -- Do not change. You may experience problems with the design file. -- #
        label1=tk.Label(self,text='Όνομα Χρήστη')
        label1.place(relx=0.02, rely=0.07, relwidth=0.41, relheight=0.09)
 
        # -- Do not change. You may experience problems with the design file. -- #
        button1=tk.Button(self,text='Είσοδος', command=lambda: controller.show_frame(PageOne))
        button1.pack(side=BOTTOM)
 
 
 
class PageOne(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent) 
        label = tk.Label(self, text="This is page 1", font=TITLE_FONT)
        label.pack(side="top", fill="x", pady=10)
 
 
        button = tk.Button(self, text="Go to the start page", command=lambda: controller.show_frame(StartPage))
        button.pack()
 
 
if __name__ == "__main__":
    app = SampleApp()
    app.mainloop()
Τελευταία διόρθωση: 12 Χρόνια 5 Μήνες πριν από STRATOS.
Πρέπει να είστε εγγεγραμμένο μέλος του Φόρουμ για να κάνετε μια δημοσίευση.
Οι ακόλουθοι χρήστες είπαν "Σε Ευχαριστώ": pmav99
Συντονιστές: pmav99
Χρόνος δημιουργίας σελίδας: 0.756 δευτερόλεπτα

Μοιράσου το!

Powered by CoalaWeb

Λίστα Ταχυδρομείου