Python3.x ve PyQt5 kullanarak randevulari online olarak kaydedecek bir program yaziyorum. Ama randevu kaydetme ekraninda baslik icin olusturdugum QLineEdit text olarak herzaman bos bir string veriyor. Haliyle QLineEdit bos birakilirsa diye yazdigim uyari kullaniciya gösteriliyor.
def home(self):
def save_app(target=None, title="", date=None, time=None, details=""):
if target == "online": # Bu kisim hep calisiyor
if title == "":
QMessageBox.information(self, "Hey!", "Fill in the blanks first!", QMessageBox.Ok)
else:
con = mysql.connect(host="89.252.186.2", port=3306, user="bademsof_mbilal25tr", passwd="k7S30j7r", db="bademsof_appointments")
cur = con.cursor()
cur.execute("""INSERT INTO appointments VALUES '{}', '{}', '{}', '{}', '{}', '{}'""".format(self.userno, title, date.toPyDate(), time.toPyTime, details, self.userID))
cur.close()
con.close()
elif target == "offline":
con = sqlite.connect("apponman.bademsof")
if accountOnline == False:
self.userinfo_label.setText("You are in offline mode! ")
elif accountOnline == True:
self.userinfo_label.setText("Welcome {}\nYour UserID: {}\nYour UserNo: {}".format(self.username, self.userID, self.userno))
self.profile_button = QPushButton("Profile", self.header_frame)
self.header_layout.addWidget(self.profile_button, 1, 2)
self.profile_button_menu = QMenu()
self.profile_button.setMenu(self.profile_button_menu)
action_1 = self.profile_button_menu.addAction("Profile")
action_2 = self.profile_button_menu.addAction("Partners")
self.center_layout.removeWidget(self.username_label)
self.username_label.deleteLater()
self.center_layout.removeWidget(self.username_entry)
self.username_entry.deleteLater()
self.center_layout.removeWidget(self.password_label)
self.password_label.deleteLater()
self.center_layout.removeWidget(self.password_entry)
self.password_entry.deleteLater()
self.center_layout.removeWidget(self.login_button)
self.login_button.deleteLater()
self.center_layout.removeWidget(self.register_button)
self.register_button.deleteLater()
self.center_layout.removeWidget(self.offline_button)
self.offline_button.deleteLater()
self.center_layout.removeWidget(self.remember_check)
self.remember_check.deleteLater()
self.home_list = QListWidget(self.centralwidget)
self.home_list.setMaximumWidth(200)
self.home_list.setFrameShape(QListWidget.NoFrame)
self.home_list.setSpacing(10)
self.home_list.setIconSize(QSize(20, 20))
self.home_list.setStyle(QStyleFactory.create("WindowsVista"))
self.home_list.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.new_online_page = QWidget()
self.active_online_page = QWidget()
self.all_online_page = QWidget()
self.new_offline_page = QWidget()
self.all_offline_page = QWidget()
self.home_stack = QStackedWidget(self.centralwidget)
self.home_stack.setStyleSheet("background-color: white;")
self.home_stack.addWidget(self.new_online_page)
#########################create_new_online_page()
layout1 = QGridLayout()
title_label = QLabel(self.new_online_page)
title_label.setText("Title:\t")
date_label = QLabel(self.new_online_page)
date_label.setText("Date:\t")
time_label = QLabel(self.new_online_page)
time_label.setText("Time:\t")
details_label = QLabel(self.new_online_page)
details_label.setText("Details:\t")
self.online_title_edit = QLineEdit(self.new_online_page)
self.online_date_edit = QDateEdit(self.new_online_page)
self.online_time_edit = QTimeEdit(self.new_online_page)
self.online_details_edit = QTextEdit(self.new_online_page)
online_save_button = QPushButton("Save", self.new_online_page)
online_save_button.clicked.connect(
partial(save_app, target="online", title=self.online_title_edit.text(), date=self.online_date_edit.date(),
time=self.online_time_edit.time(), details=self.online_details_edit.toPlainText())) # Burada texti aliyorum
# stackspacer = QSpacerItem(40, 20, vPolicy=QSizePolicy.Ignored)
layout1.addWidget(title_label, 0, 0, 1, 1)
layout1.addWidget(date_label, 1, 0, 1, 1)
layout1.addWidget(time_label, 2, 0, 1, 1)
layout1.addWidget(details_label, 3, 0, 1, 10)
layout1.addWidget(self.online_title_edit, 0, 1, 1, 9)
layout1.addWidget(self.online_date_edit, 1, 1, 1, 9)
layout1.addWidget(self.online_time_edit, 2, 1, 1, 9)
layout1.addWidget(self.online_details_edit, 4, 0, 1, 10)
layout1.addWidget(online_save_button, 5, 9, 1, 1)
# layout1.addItem(stackspacer, 6, 5, 1, 1)
self.online_date_edit.setDateTime(QDateTime.currentDateTime())
# date_edit.setMinimumDate(QDateTime.currentDateTime())
self.new_online_page.setLayout(layout1)
#########################create_active_online_page()
#########################create_all_online_page()
#########################create_new_offline_page()
layout4 = QGridLayout()
title_label = QLabel(self.new_offline_page)
title_label.setText("Title:\t")
date_label = QLabel(self.new_offline_page)
date_label.setText("Date:\t")
time_label = QLabel(self.new_offline_page)
time_label.setText("Time:\t")
details_label = QLabel(self.new_offline_page)
details_label.setText("Details:\t")
self.offline_title_edit = QLineEdit(self.new_offline_page)
self.offline_date_edit = QDateEdit(self.new_offline_page)
self.offline_time_edit = QTimeEdit(self.new_offline_page)
self.offline_details_edit = QTextEdit(self.new_offline_page)
offline_save_button = QPushButton("Save", self.new_offline_page)
offline_save_button.clicked.connect(
partial(save_app, target="offline", title=self.offline_title_edit.text(), date=self.offline_date_edit.date(),
time=self.offline_time_edit.time(), details=self.offline_details_edit.toPlainText()))
layout4.addWidget(title_label, 0, 0, 1, 1)
layout4.addWidget(date_label, 1, 0, 1, 1)
layout4.addWidget(time_label, 2, 0, 1, 1)
layout4.addWidget(details_label, 3, 0, 1, 10)
layout4.addWidget(self.offline_title_edit, 0, 1, 1, 9)
layout4.addWidget(self.offline_date_edit, 1, 1, 1, 9)
layout4.addWidget(self.offline_time_edit, 2, 1, 1, 9)
layout4.addWidget(self.offline_details_edit, 4, 0, 1, 10)
layout4.addWidget(offline_save_button, 5, 9, 1, 1)
self.offline_date_edit.setDateTime(QDateTime.currentDateTime())
self.new_offline_page.setLayout(layout4)
#########################create_all_offline_page()
self.home_stack.addWidget(self.active_online_page)
self.home_stack.addWidget(self.all_online_page)
self.home_stack.addWidget(self.new_offline_page)
self.home_stack.addWidget(self.all_offline_page)
self.center_layout.addWidget(self.home_list, 1, 0, 20, 1)
self.center_layout.addWidget(self.home_stack, 1, 1, 19, 3)
self.home_list.addItem(QListWidgetItem(QIcon("new_online_icon.png"), "New Appointment"))
self.home_list.addItem(QListWidgetItem(QIcon("active_online_icon.png"), "Active Appointments"))
self.home_list.addItem(QListWidgetItem(QIcon("all_online_icon.png"), "All Appointmens"))
self.home_list.addItem(QListWidgetItem(QIcon("new_offline_icon.png"), "New Offline Appointment"))
self.home_list.addItem(QListWidgetItem(QIcon("all_offline_icon.png"), "Offline Appointments"))
def display(i):
self.home_stack.setCurrentIndex(i)
self.home_list.currentRowChanged.connect(display)
Nedendir? Nasil cözerim? Simdiden Tesekkürler…