Last active
August 29, 2015 14:17
-
-
Save stripe-q/c8de2bb8c68c09580f9e to your computer and use it in GitHub Desktop.
섭씨화씨변환기(Qt) 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import QApplication, QWidget | |
from temperature_object import Ui_Form | |
class MyForm(QWidget): | |
def __init__(self): | |
super(MyForm2, self).__init__() | |
# UI 셋업 과정을 위해서는 Ui_Form 인스턴스를 만들고, setupUi를 호출해야 한다. | |
# 이 때 넘겨지는 인자는 자신 혹은 특정한 QWidget 인스턴스이다. | |
self.ui = Ui_Form() | |
self.ui.setupUi(self) | |
def convert_cel_to_frn(self): | |
cel = self.ui.cel_box.value() | |
frn = (cel * 1.8) + 32 | |
self.ui.frn_box.setValue(frn) | |
def convert_frn_to_cel(self): | |
frn = self.ui.frn_box.value() | |
cel = (frn - 32) / 1.8 | |
self.ui.cel_box.setValue(cel) | |
app = QApplication(sys.argv) | |
ui = MyForm() | |
ui.show() | |
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import QApplication, QWidget | |
from temperature_object import Ui_Form | |
class MyForm2(Ui_Form, QWidget): | |
def __init__(self): | |
super(MyForm, self).__init__() | |
self.setupUi(self) | |
def convert_cel_to_frn(self): | |
cel = self.cel_box.value() | |
frn = (cel * 1.8) + 32 | |
self.frn_box.setValue(frn) | |
def convert_frn_to_cel(self): | |
frn = self.frn_box.value() | |
cel = (frn - 32) / 1.8 | |
self.cel_box.setValue(cel) | |
def setupUi(self, Form): | |
super(MyForm, self).setupUi(Form) | |
self.cel_box.setValue(25) | |
app = QApplication(sys.argv) | |
ui = MyForm2() | |
ui.show() | |
sys.exit(app.exec_()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>260</width> | |
<height>170</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>Form</string> | |
</property> | |
<widget class="QWidget" name="verticalLayoutWidget"> | |
<property name="geometry"> | |
<rect> | |
<x>10</x> | |
<y>10</y> | |
<width>272</width> | |
<height>151</height> | |
</rect> | |
</property> | |
<layout class="QVBoxLayout" name="verticalLayout"> | |
<property name="sizeConstraint"> | |
<enum>QLayout::SetMaximumSize</enum> | |
</property> | |
<item> | |
<spacer name="verticalSpacer_2"> | |
<property name="orientation"> | |
<enum>Qt::Vertical</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>20</width> | |
<height>40</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<spacer name="horizontalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>40</width> | |
<height>20</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
<item> | |
<widget class="QDoubleSpinBox" name="cel_box"> | |
<property name="alignment"> | |
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
</property> | |
<property name="suffix"> | |
<string> C</string> | |
</property> | |
<property name="decimals"> | |
<number>2</number> | |
</property> | |
<property name="minimum"> | |
<double>-273.000000000000000</double> | |
</property> | |
<property name="maximum"> | |
<double>100000000.000000000000000</double> | |
</property> | |
<property name="value"> | |
<double>25.000000000000000</double> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QLabel" name="label"> | |
<property name="text"> | |
<string><--></string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<widget class="QDoubleSpinBox" name="frn_box"> | |
<property name="alignment"> | |
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
</property> | |
<property name="suffix"> | |
<string> F</string> | |
</property> | |
<property name="decimals"> | |
<number>2</number> | |
</property> | |
<property name="minimum"> | |
<double>-495.399999999999977</double> | |
</property> | |
<property name="maximum"> | |
<double>180000032.000000000000000</double> | |
</property> | |
<property name="value"> | |
<double>77.000000000000000</double> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<spacer name="horizontalSpacer_2"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>40</width> | |
<height>20</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
</layout> | |
</item> | |
<item> | |
<spacer name="verticalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Vertical</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>20</width> | |
<height>40</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
</layout> | |
</widget> | |
</widget> | |
<resources/> | |
<connections> | |
<connection> | |
<sender>cel_box</sender> | |
<signal>valueChanged(double)</signal> | |
<receiver>Form</receiver> | |
<slot>convert_cel_to_frn()</slot> | |
<hints> | |
<hint type="sourcelabel"> | |
<x>88</x> | |
<y>80</y> | |
</hint> | |
<hint type="destinationlabel"> | |
<x>252</x> | |
<y>60</y> | |
</hint> | |
</hints> | |
</connection> | |
<connection> | |
<sender>frn_box</sender> | |
<signal>valueChanged(double)</signal> | |
<receiver>Form</receiver> | |
<slot>convert_frn_to_cel()</slot> | |
<hints> | |
<hint type="sourcelabel"> | |
<x>190</x> | |
<y>88</y> | |
</hint> | |
<hint type="destinationlabel"> | |
<x>255</x> | |
<y>105</y> | |
</hint> | |
</hints> | |
</connection> | |
</connections> | |
<slots> | |
<slot>convert_cel_to_frn()</slot> | |
<slot>convert_frn_to_cel()</slot> | |
</slots> | |
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Form implementation generated from reading ui file 'temperatur.ui' | |
# | |
# Created by: PyQt5 UI code generator 5.4.1 | |
# | |
# WARNING! All changes made in this file will be lost! | |
from PyQt5 import QtCore, QtGui, QtWidgets | |
class Ui_Form(object): | |
def setupUi(self, Form): | |
Form.setObjectName("Form") | |
Form.resize(260, 170) | |
self.verticalLayoutWidget = QtWidgets.QWidget(Form) | |
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 272, 151)) | |
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") | |
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) | |
self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetMaximumSize) | |
self.verticalLayout.setContentsMargins(0, 0, 0, 0) | |
self.verticalLayout.setObjectName("verticalLayout") | |
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) | |
self.verticalLayout.addItem(spacerItem) | |
self.horizontalLayout = QtWidgets.QHBoxLayout() | |
self.horizontalLayout.setObjectName("horizontalLayout") | |
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | |
self.horizontalLayout.addItem(spacerItem1) | |
self.cel_box = QtWidgets.QDoubleSpinBox(self.verticalLayoutWidget) | |
self.cel_box.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) | |
self.cel_box.setDecimals(2) | |
self.cel_box.setMinimum(-273.0) | |
self.cel_box.setMaximum(100000000.0) | |
self.cel_box.setProperty("value", 25.0) | |
self.cel_box.setObjectName("cel_box") | |
self.horizontalLayout.addWidget(self.cel_box) | |
self.label = QtWidgets.QLabel(self.verticalLayoutWidget) | |
self.label.setObjectName("label") | |
self.horizontalLayout.addWidget(self.label) | |
self.frn_box = QtWidgets.QDoubleSpinBox(self.verticalLayoutWidget) | |
self.frn_box.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) | |
self.frn_box.setDecimals(2) | |
self.frn_box.setMinimum(-495.4) | |
self.frn_box.setMaximum(180000032.0) | |
self.frn_box.setProperty("value", 77.0) | |
self.frn_box.setObjectName("frn_box") | |
self.horizontalLayout.addWidget(self.frn_box) | |
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) | |
self.horizontalLayout.addItem(spacerItem2) | |
self.verticalLayout.addLayout(self.horizontalLayout) | |
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) | |
self.verticalLayout.addItem(spacerItem3) | |
self.retranslateUi(Form) | |
self.cel_box.valueChanged['double'].connect(Form.convert_cel_to_frn) | |
self.frn_box.valueChanged['double'].connect(Form.convert_frn_to_cel) | |
QtCore.QMetaObject.connectSlotsByName(Form) | |
def retranslateUi(self, Form): | |
_translate = QtCore.QCoreApplication.translate | |
Form.setWindowTitle(_translate("Form", "Form")) | |
self.cel_box.setSuffix(_translate("Form", " C")) | |
self.label.setText(_translate("Form", "<-->")) | |
self.frn_box.setSuffix(_translate("Form", " F")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment