Це відео не доступне.
Перепрошуємо.

Multiple Screens in PyQt5: Switch screens without opening a new window

Поділитися
Вставка
  • Опубліковано 18 сер 2024
  • Learn how to switch between multiple screens inside one window in PyQt5. Create a PyQt5 GUI with Python with a button that allows you to go to another screen or window.
    In this video, you will:
    - Use PyQt5 and QtDesigner
    - Create an application that has multiple screens
    - Go from one screen to another inside the application
    For more info:
    - Install and Setup PyQt5 and QtDesigner: • Install and Setup PyQt...
    - PyQt5 QtDesigner Login and Signup Forms tutorial: for COMPLETE beginners • PyQt5 QtDesigner Login...
    Source code: github.com/cod...
    Contact me at: code.first.io@gmail.com
    *************
    *Tags*
    PyQt5 tutorial
    PyQt5 form
    PyQt5 Designer
    Qt Designer
    Qt GUI tutorial
    GUI tutorial Python
    Graphical User Interface Python
    Python tutorial

КОМЕНТАРІ • 77

  • @the1anonymouse
    @the1anonymouse 3 роки тому +46

    Very good tutorial! However for actually moving between the windows that need to be updated, it would be better to use the insertWidget and removeWidget methods. If you keep adding widgets and incrementing the stack, the old widgets are not deleted and the stack will simply continue to grow and use much more memory than it needs to

    • @kuahara
      @kuahara Рік тому

      Do you have a working example of how to do this?

    • @drsoosstttm8375
      @drsoosstttm8375 Рік тому +7

      @@kuahara you actually dont have to do anything crazy, just a line under the widget.addWidget add a widget.removeWidget
      e.g
      line 1: widget.addWidget(screen2)
      line 2 :widget.removeWidget(screen1)
      in my program, the remove widget stopped the program from consuming too much memory
      have a good day

    • @kuahara
      @kuahara Рік тому

      @@drsoosstttm8375 Thanks. I'll check that out later. I started using +1 and -1, but that just moves the index around. It doesn't free up memory. It's been over a week, I don't remember what went wrong when I tried insertWidget per the first commenter.

    • @miledmohamed2250
      @miledmohamed2250 6 місяців тому

      @@drsoosstttm8375 Could you please provide more details? I suspect that it might be memory-consuming, but I haven't found a solution for it yet.

    • @spinj3307
      @spinj3307 4 місяці тому

      You are very right thank you, but there are situations as well where you might want to use stacked widgets for example if u have few finite number of screens and u want to work on them while using qt designer, on one window.

  • @someoneontheinternetuvenev6268
    @someoneontheinternetuvenev6268 3 роки тому +10

    FINALLY FOUND A GENUINE TUTORIAL. THANK YOU!

  • @muhammadali-cv3uq
    @muhammadali-cv3uq 3 роки тому +14

    Why you don't have subtracted 1 when moving from screen 2 to 1 in index?

  • @nqobiledlamini5253
    @nqobiledlamini5253 2 місяці тому

    Thank you so much your help, this is the only video I find helpful in this situation ❤❤

  • @pedrowegner9167
    @pedrowegner9167 2 роки тому +5

    This video is helpfull, although I have a question about switching screens. For instance, in this video both of classes are on the same module, right? But in a biggest application, how can I do the switch screen? I have found no way to make swicht screen, which is saved in different modules.

  • @someoneontheinternetuvenev6268
    @someoneontheinternetuvenev6268 3 роки тому +3

    Hey I have a question, doesn't the 2nd method of creating new instances cause memory leaks?

  • @Atharva_Vashist
    @Atharva_Vashist 3 роки тому +1

    Thank you very much, this video deserves so many likes

  • @hungleinh2746
    @hungleinh2746 Рік тому

    Thank you so much, I found this tutorial for a long time and finally, I found it

  • @PavanTripathi-rj7bd
    @PavanTripathi-rj7bd 10 місяців тому

    Thanks for the wonderful explanation. Exactly what I needed.

  • @abilovestotrade
    @abilovestotrade Рік тому

    Hi, thank you very much for this guide. Helped me a lot with PySide6.
    Here is a working example of my code which removes the current active Widget to free up memory and then adds a new widget.
    KEEP IN MIND:
    By doing this you will lose the data of the widget which is being removed. Example of if your first widget is a login screen then you do not want to do this because it will remove their login ID data that the user might have entered, he/she will have to enter everything again. In that instance switching the index will do the trick.
    def screen2(self):
    s2 = screen2()
    widget.removeWidget(wid.currentWidget())
    widget.addWidget(s2)
    going back to screen 1:
    def screen1(self):
    s1 = screen1()
    widget.removeWidget(wid.currentWidget())
    widget.addWidget(s1)
    app = QApplication(sys.argv)
    widget = QStackedWidget()
    s1 = screen1()
    widget.addWidget(s1)
    widget.setFixedSize(1124, 844)
    widget.show()
    app.exec()

  • @hussainabbas1341
    @hussainabbas1341 2 роки тому

    Thank You, Your explanation is so descriptive, keep going.

  • @tommysellbee
    @tommysellbee 3 роки тому +1

    Hi I have a question, how do I handle the closeEvent of the QStackedWidget?

  • @anonymousghost5384
    @anonymousghost5384 2 роки тому +2

    When ya adding widgets all time whenever ya switch windows the program use more memory
    Shouldn't ya remove widget to get back
    Am i wrong?

  • @wickedblue3218
    @wickedblue3218 3 роки тому +1

    Thank you... i was looking for something like this!!!!

  • @xlobo9822
    @xlobo9822 11 місяців тому

    Thank you for knowing your content, and I have already subscribed to it.
    I became another fan who promotes you to my friend in Korea. 💯 감사합니다

  • @aNImALzZ217
    @aNImALzZ217 3 роки тому +1

    I love you so much like you don't even know. THANK YOU THANK YOU

  • @-mathsinsinhala8126
    @-mathsinsinhala8126 2 роки тому +1

    Your tutorial is very good, can you do another tutorial to open 2nd window in mdi area, mdi area when clicking file menu action

  • @timurka0583
    @timurka0583 Рік тому

    Thank you very much! I had a problem that I couldn't switch windows with Controller, after some changes it stopped working. Even though I'm Russian, I understood everything perfectly.

  • @digitalmachine0101
    @digitalmachine0101 4 місяці тому

    Good information

  • @Crazy_octo
    @Crazy_octo 5 місяців тому

    really useful tutorial thx
    👍

  • @nadirb229
    @nadirb229 3 роки тому +2

    Hi, Thank you for the simple and short and informative tutorial
    You are choosing Very interesting tutorial subjects!
    As a beginner i m straggling with Multi-Window subject, I searched a lot and didn't find the answer!
    I made a MainWindow and i need to make a Dialog window opens.. the problem is the Dialog or Dialogs open in a separate window in window Taskbar!! help please

    • @codefirstwithhala
      @codefirstwithhala  3 роки тому +2

      Hi! I think trying to follow the tutorial should help. This way, we go to a different screen without opening a new window in the taskbar! Let me know if you have any more questions

    • @nadirb229
      @nadirb229 3 роки тому

      @@codefirstwithhala i watched your video twice! What i need is: i made an App with tabs each tab contains a table (MySql) i need a dialog to insert and modify data when i double click a line in any table (a small dialog window) within the mainWindow not in separate precess

  • @gaburuukun2617
    @gaburuukun2617 5 місяців тому

    Question, how about i have 3 different python file and i want in my main when i click this button one of my 3 python file will appear

  • @robpersonalteacher4162
    @robpersonalteacher4162 2 роки тому +1

    You are fantastic!!!! I loved how well you explained everything and the fact that you focus on functionality.

  • @kayombo1001
    @kayombo1001 3 роки тому +2

    Hi, thank you for sharing your knowledge, I was realy looking for this lesson, for ather hand, could you tell me please if it is possible to disable the title bar in PQT5? Sorry for my broken english, Iam speaking from Angola and here we speak Portuguese.

    • @erbhargavvyas
      @erbhargavvyas 3 роки тому +1

      You can disable the title bar using
      self.window.setWindowFlag(Qt.FramelessWindowHint)

  • @eyupcvs9249
    @eyupcvs9249 Рік тому

    I love youuu,thanks a lot

  • @abdelrahmanfekri8876
    @abdelrahmanfekri8876 Рік тому

    Very good tutorial

  • @ayushmaanyadav4069
    @ayushmaanyadav4069 2 роки тому

    Now I can use this concept to implement tabs feature in my project.(making a web browser btw)

  • @apo0orva
    @apo0orva 3 роки тому +2

    Hi, I tried this program on my mac, but it raises an error. After searching on the internet for a long, came to know that " loadUi " (from PyQt5.uic import loadUi) is not available on mac. So can you make a video on how to do this same program without using loadUi ? It would be very helpful :)

    • @rbgspar0896
      @rbgspar0896 3 роки тому +1

      Hi Apoorva, did you find a solution on this issue ?

    • @apo0orva
      @apo0orva 3 роки тому +1

      @@rbgspar0896 I exported the .ui file to .py file and created a different class for changing screen but sometimes it doesn't work as expected. 🙂

    • @rbgspar0896
      @rbgspar0896 3 роки тому

      @@apo0orva Cool, thanks!

  • @11bomon48
    @11bomon48 Рік тому

    Thank you so much!

  • @diegohernandezestrada4328
    @diegohernandezestrada4328 Рік тому

    my pycharm environment cant find the pyqt5.uic import loadUi, i only installesd pyqt and the tools as python packages

  • @accelwatchingfun9560
    @accelwatchingfun9560 3 роки тому +1

    First of all, thank you very much
    Just a question
    If i try to put the Screen2 thing inside of the function, it says "UnboundLocalError: local variable 'Calculator' referenced before assignment". Did i miss something?

  • @tattapontippayachan443
    @tattapontippayachan443 2 роки тому

    Thank you very much

  • @uly3213
    @uly3213 Рік тому

    how to do it if i select more MainWindows in QtDesigner?

  • @abdullahbutt324
    @abdullahbutt324 2 роки тому

    Can you teach us how to open the main window screen from this button method. It doesnt open it in that case

  • @DyneGadante
    @DyneGadante Рік тому

    How does she have it so that you can edit both windows side by side in the designer?

  • @orhansrml
    @orhansrml 3 роки тому +1

    First of all thank you.
    I have a question. You define widget variable at the buttom of your code but you use it in the class above. When I do the same thing, it says "widget not defined".
    Can anyone help?

    • @sisik96
      @sisik96 3 роки тому

      Same here

    • @dimavarchuc2046
      @dimavarchuc2046 2 роки тому

      if you have "widget = QStackedWidget()" in the main function then delete main function and place this peace of code to "if __name__ == "__main__":" (It helped me)

  • @blueshoreboutique5382
    @blueshoreboutique5382 Рік тому

    What if there are 100 screens to create? It will load all 100 screens into memory before display....

  • @marcelocardosorabelo3623
    @marcelocardosorabelo3623 2 роки тому

    you is exelent! thank you .

  • @deeparghchatterjee2600
    @deeparghchatterjee2600 2 роки тому

    Hey, this is very helpful tutorial, although as I followed through the whole process, my gotoScreen2 function shows error as: "MainWindow object has no attribute gotoScreen2". Please help

  • @Oussama-qp2hh
    @Oussama-qp2hh Рік тому

    please help me
    how i passing data between windows

  • @gfrsaaaar4575
    @gfrsaaaar4575 2 роки тому

    Can you show how to build the App to fill the birthdate?

  • @juanemiliogarcia1843
    @juanemiliogarcia1843 3 роки тому

    Hello, where I can found documentation about this?

  • @mr.morgan1002
    @mr.morgan1002 3 роки тому

    thanks for this video

  • @bryanesquivel6062
    @bryanesquivel6062 3 роки тому

    Thank you!!

  • @Harsh-se1gx
    @Harsh-se1gx 3 роки тому

    Thank you.

  • @spiffjekey-green4034
    @spiffjekey-green4034 10 місяців тому

    I just wish there's a c++ version of this but for QT6

  • @kittytangsze
    @kittytangsze 3 роки тому

    how to split into two or three python file?

  • @SyedDanishTech
    @SyedDanishTech 2 роки тому

    Thank You

  • @hokcheunghung7769
    @hokcheunghung7769 3 роки тому

    thank you

  • @sherrilblackmon7465
    @sherrilblackmon7465 3 роки тому

    I am an old man who speaks middle American English and I don't hear well. I love your voice and your tutorials hit enough of the topics-subtopics to be of very much use to me (I'm learning Python as a project for myself).
    My issue is you talk a little too fast for me to get it all without repeatedly rewinding the video.
    Is there a facility whereby I might turn down the playback speed?

    • @gx4
      @gx4 3 роки тому +2

      When you hover over the video, you can see a settings icon in the bottom right corner. Click on that, then click on playback speed and adjust it to your likings.

  • @rabbitazteca23
    @rabbitazteca23 3 роки тому +1

    So if I don't have QT designer and didn't make those UI designs in the first place, then I can't do this? I was hoping you'd show this with PURE code.

    • @alexandarjelenic7718
      @alexandarjelenic7718 3 роки тому +6

      Qt designer is free, you can also use qt creator which is the newer version and it is also free. there are many videos that do the ui design with pure code. Believe me it is not an attactive option. loading the ui is by far the best, it is so easy to make a change or move things around. so it is better for maintenance!

    • @someoneontheinternetuvenev6268
      @someoneontheinternetuvenev6268 3 роки тому

      just create a button and call a function from it, the same thing

  • @erbhargavvyas
    @erbhargavvyas 3 роки тому

    Nice concept But every time adding new window is not a good idea also it is not closing the previous instance so it will stackup the memory if the user keep doing back and forth. May be destroying the closing window or just moving the index 1 and 2 is required.

    • @accelwatchingfun9560
      @accelwatchingfun9560 3 роки тому

      Could you please explain it more in detail? Or better, because i am an absolute (I kinda started today with PyQt) beginner, do you know how to avoid stackups?

    • @erbhargavvyas
      @erbhargavvyas 3 роки тому

      @@accelwatchingfun9560 I am also a new bee in pyqt. But some how you can go back to array and show it at position 0 and position 1. One should not keep the array incrementing again and again.

    • @accelwatchingfun9560
      @accelwatchingfun9560 3 роки тому

      @@erbhargavvyas First of all....Damn, that was a quick response. Wish that would happen everytime XD. Secondyl, thank you for the answer. Do you think it is possible to do "-1" and not "+1"?. And third, thank you ^^

    • @someoneontheinternetuvenev6268
      @someoneontheinternetuvenev6268 3 роки тому

      @@erbhargavvyas I was thinking the same thing, I'm building a production application right now and I dont know how to get around this, did you find anything by any chance?

    • @someoneontheinternetuvenev6268
      @someoneontheinternetuvenev6268 3 роки тому

      @@accelwatchingfun9560 no, that will get you out of range and crash your application

  • @cinquecento1985
    @cinquecento1985 2 роки тому

    fYi: Sourcecode Link is wrong. I love the fact that the Qt5 Designer is a copy of the Visual Basic 6 Designer, which is the best Editor UI ever, despite beeing over 25 years old.

  • @sky4131
    @sky4131 2 роки тому

    Машалла

  • @mseroglu47
    @mseroglu47 3 роки тому

    Çok laf az iş