#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0

    Post Newbie questions.


    I am new to python and i have few questions.


    1.what is purpose of
    Code:
    try:    except:
    ( if you can give example)

    2.If i want to make a gui program, what's the easiest interface / visual designer to use?

    3.What are classes, how to use them and what's their purpose?

    4. What does this code actualy do? ( brf is stack of words) ( urls )
    Code:
        for admin in brf:             admin = admin.replace("\n","")             admin = "/" + admin
    5. after i create a gui interface at qt designer, can i compile it to python and then edit the code to suit it's main function, cuz' in Qt designer i can only make gui and there isn't place where i can actualy edit the source code in python while im designing it.

    Please give me some tips from which i can effectively learn python, and make gui programs
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,739
    Rep Power
    1959
    One good place to start is to look at the documentation:
    explaining try and except
    explaining classes
    explaining the for loop
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    620
    Rep Power
    65
    The PyQT/PySide Designer program spits out XML code, which can be changed to Python code with an included utility. Actually, it's simpler to just go with the XML code directly from within Python/PyQT code.

    Here is XML code generated with Designer. I saved it as 'combobox2.ui' :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>Form</class>
     <widget class="QWidget" name="Form">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>392</width>
        <height>129</height>
       </rect>
      </property>
      <property name="font">
       <font>
        <family>Arial</family>
        <pointsize>12</pointsize>
       </font>
      </property>
      <property name="windowTitle">
       <string>Select a pasta from the combo box</string>
      </property>
      <widget class="QComboBox" name="comboBox">
       <property name="geometry">
        <rect>
         <x>20</x>
         <y>10</y>
         <width>181</width>
         <height>22</height>
        </rect>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections>
      <connection>
       <sender>comboBox</sender>
       <signal>currentIndexChanged(QString)</signal>
       <receiver>Form</receiver>
       <slot>setWindowTitle(QString)</slot>
       <hints>
        <hint type="sourcelabel">
         <x>136</x>
         <y>21</y>
        </hint>
        <hint type="destinationlabel">
         <x>136</x>
         <y>45</y>
        </hint>
       </hints>
      </connection>
     </connections>
    </ui>
    Here is how you incorporate the .ui file in Python/PyQT code:
    Code:
    # run_combobox2.py
    # a simple loader for .ui XML files generated with QTDesigner
    # the XML file "combobox2.ui"
    # contains a QWidget Form with a QComboBox on it
    # the QComboBox signal is connected to the Form slot
    # setWindowTitle(QString) via currentIndexChanged(QString)
    
    import sys
    
    from PyQt4 import QtGui, uic
    
    
    app = QtGui.QApplication(sys.argv)
    widget = uic.loadUi("combobox2.ui")
    widget.show()
    
    combo = widget.comboBox
    # load the combobox with some string items
    pasta_list = ['Spaghetti', 'Fettuccine', 'Ziti', 'Penne', 'Lasagne']
    for pasta in pasta_list:
        combo.addItem(pasta)
    
    app.exec_()
    You can edit the XML code directly, but you better know what you are doing.
    Last edited by Dietrich; December 6th, 2012 at 09:18 PM.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    Name an interest of yours---preferably somehow related to programming. Maybe we can motivate classes and exceptions via that vehicle.

    To answer your question 4 I'd need to know about brf.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    Originally Posted by b49P23TIvg
    To answer your question 4 I'd need to know about brf.
    Unless there's more to it, what's in brf doesn't matter as that code does nothing (useful) at all. Each iteration of the loop will just assign the name "admin" to an element of brf, then reassign the name "admin" to a new string (which is equal to the previous string with newlines removed), and then reassign the name again (to the previous string with a forward slash prepended) and then...not do anything with it.

    It seems like what it's trying to do is change the elements of brf, but that's not what it's doing.
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    I'm quite sure you can design a class for which

    admin.replace("\n","")

    attempts to delete your file system before nothing else happens.

    We don't know the type of admin. We don't know what its replace method does.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo