Bonjour à tous,

Je met mets un peu au python, et à PyQt pour le coté graphique.
J'ai créé un .ui avec quelques boutons, rien de sorcier (sous Qt Designer)

Voici mon code python :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys
 
from PyQt5 import uic
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtWidgets import QApplication, QWidget,QMainWindow
 
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = uic.loadUi("testpython.ui", self)
        self.echantillonage_button.clicked.connect(self.CalculEch)
 
def CalculEch(self):
        focale = int(self.focale_box.toPlainText())
        taille_pixel = float(self.taille_px.value())
        echantillonage = 206 *  taille_pixel / float(taille_pixel)
        echantillonage_string = "Lechantillonage est de: " + str(echantillonage)
        self.LCD_echantillonage.setText(ehantillonage__string)
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())
et mon code ui :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1426</width>
    <height>1091</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QPushButton" name="echantillonage_button">
    <property name="geometry">
     <rect>
      <x>250</x>
      <y>70</y>
      <width>171</width>
      <height>46</height>
     </rect>
    </property>
    <property name="text">
     <string>Echantillonage</string>
    </property>
   </widget>
   <widget class="QTextEdit" name="focale_box">
    <property name="geometry">
     <rect>
      <x>40</x>
      <y>50</y>
      <width>141</width>
      <height>41</height>
     </rect>
    </property>
   </widget>
   <widget class="QDoubleSpinBox" name="taille_px">
    <property name="geometry">
     <rect>
      <x>40</x>
      <y>110</y>
      <width>141</width>
      <height>41</height>
     </rect>
    </property>
    <property name="maximum">
     <double>20.000000000000000</double>
    </property>
    <property name="value">
     <double>5.400000000000000</double>
    </property>
   </widget>
   <widget class="QLCDNumber" name="LCD_echantillonage">
    <property name="geometry">
     <rect>
      <x>40</x>
      <y>170</y>
      <width>141</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Gadugi</family>
      <weight>75</weight>
      <bold>true</bold>
     </font>
    </property>
    <property name="smallDecimalPoint">
     <bool>false</bool>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1426</width>
     <height>38</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
J'obtiens l'erreur suivante :

AttributeError: 'module' object has no attribute 'QApplication' .

Connaissez vous une idée du pourquoi ?

En vous remerciant par avance !