-1

I am new to PyQt I have done some GUI programming in Tkinter, I am trying to learn how to open a new frame when I click a button. All I could find on the internet was buttons opening another window all together. I want a translation of something like this tkinter code to pyqt4 code

class foo(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        #favicon
        #tk.Tk.iconbitmap(self, default="@/home/sahil/PycharmProjects/gui/fav.ico")

        #changing title of window
        tk.Tk.wm_title(self, "graph")

        #we're building the container that'll contain all the elements
        #Frame is a window
        container = tk.Frame(self)

        #side aligns it to the direction0000000
        #fill fills the entire whitespace
        #exapnd lets you fill the whitespaces if the window is expanded
        container.pack(side="top",fill="both",expand=True)

        #0 is the row number
        #weight is importance
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
self.frames = {}

        #creating a tuple of frames added into the program and passing them through
        for F in (StartPage, PageOne, GraphPage):

            frame = F(container, self)

            #refrencing the page in self.FRAMES
            self.frames[F] = frame

            #North South East West
            frame.grid(row=0, column=0, sticky="nsew")

        #calling a funcction to display the page
        self.show_frame(StartPage)

    def show_frame(self, controller):
        #this corresponds to SELF.FRAMES
        #its looking for the value in FRAMES and raising it
        frame = self.frames[controller]
        #raising the page you called
        frame.tkraise()



class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        newFont = ("Verdana", 12)
        tk.Frame.__init__(self,parent)
        label = tk.Label(self,text="""ALPHA BITCOIN TRADING APPLICATION! There are no warranties for data loss or anytihng""", font=newFont)
        label.pack(padx=10, pady=10)

        button1 = ttk.Button(self, text="Agree", command=lambda: controller.show_frame(GraphPage))
        button1.pack()

        button2 = ttk.Button(self, text="Disagree", command=quit)
        button2.pack()

        button3 = ttk.Button(self, text="PageOne", command=lambda: controller.show_frame(PageOne))
        button3.pack()


app = foo()
app.geometry("800x600")
app.config(background="black")
ani = animation.FuncAnimation(figure, animate, interval=10000)
app.mainloop()

I have tried a lot of pyqt4 code some written by others and all it did was just open another window, not a frame

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sahil
  • 1,387
  • 14
  • 41
  • Your question is not suitable for SO, we do not do code translations here. Please read the following for a good question: https://stackoverflow.com/help/how-to-ask – eyllanesc Jul 17 '17 at 02:36
  • Your question is similar to asking for a tutorial, what you could do to improve your question is to show what you have tried in pyqt. – eyllanesc Jul 17 '17 at 02:37
  • i am not asking someone else to do my work, i am asking for a nudge in the right direction to how to open a frame and not a window and if you do know how to do that please answer it. Alright. I posted my tkinter code so that someone could say yeah that For loop over there here's what you can do in Pyqt to duplicate that write the whole code and spoon feed me @eyllanesc – Sahil Jul 17 '17 at 02:39
  • In addition you must do a search before asking, the question that you have been asked many questions, for example: https://stackoverflow.com/questions/43171693/in-python-how-do-i-open-a-new-window-by-clicking-a-button-in-a-main-window-usin – eyllanesc Jul 17 '17 at 02:39
  • another question: https://stackoverflow.com/questions/36768033/pyqt-how-to-open-new-window – eyllanesc Jul 17 '17 at 02:39
  • If you show what you have tried in pyqt I will try to help you. :P – eyllanesc Jul 17 '17 at 02:40
  • another similar question: https://stackoverflow.com/questions/14410152/pyqt-on-click-open-new-window – eyllanesc Jul 17 '17 at 02:42
  • 1
    I understand that you do not want to ask us to make your code but unfortunately you are doing it. – eyllanesc Jul 17 '17 at 02:43
  • let me edit and add my pyqt code @eyllanesc – Sahil Jul 17 '17 at 02:45
  • Great, I'll be waiting. – eyllanesc Jul 17 '17 at 02:46

1 Answers1

-1

this should work for you and @Eyllanesc is right your question is framed like you're asking for a tutorial even if you don't mean it to be.

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *


class first(QWidget):
    def __init__(self, parent=None):
        super(first, self).__init__(parent)
        # mainwindow.setWindowIcon(QtGui.QIcon('PhotoIcon.png'))
        self.agree = QPushButton('Agree', self)
        self.agree.move(180, 400)
        self.button2 = QPushButton('Disagree', self)
        self.button2.move(270,400)


class second(QWidget):
    def __init__(self, parent=None):
        super(second, self).__init__(parent)
        self.btn = QPushButton("previous", self)
        self.btn.move(100, 350)
        self.greet = QLabel("second",self)


class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setGeometry(50, 50, 400, 450)
        self.setFixedSize(400, 450)
        self.setWindowIcon(QIcon("favicon.png"))
        self.startfirst()

    def startsecond(self):
        self.ToolTab = second(self)
        self.setWindowTitle("second")
        self.setCentralWidget(self.ToolTab)
        self.ToolTab.btn.clicked.connect(self.startfirst)
        self.show()

    def startfirst(self):
        self.Window = first(self)
        self.setWindowTitle("first")
        self.setCentralWidget(self.Window)
        self.Window.agree.clicked.connect(self.startsecond)
        self.Window.button2.clicked.connect(QCoreApplication.instance().quit)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()
    sys.exit(app.exec_())