Python Forum
return/capture the selected date from QDateEdit's calendar?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return/capture the selected date from QDateEdit's calendar?
#1
I would like to create a pop up calendar and then select a date to print out the selected Date. So far,I only able to create it using QDateEdit but fail to return the selected date.

below are popupCalendar but not able to select and return the date into label.
def setupUi(self):
        self.calendar1=QDateEdit(self)
        self.calendar1.setCalendarPopup(True)
        self.calendar1.dateChanged.connect(self.show_date)
        selectedDate=self.calendar1.dateChanged 
        print(selectedDate) # check signal
        self.Date_label = QLabel(self)
        self.Date_label.move(50,320)
        self.Date_label.setText(selectedDate.toString())
                    
    def show_date(self, selectedDate):
        self.Date_label.setText(selectedDate.toString())
fail to execute self.Date_label.setText(selectedDate.toString) ,how to return the selected date? Sad Sad
Reply
#2
You are right in not showing hundreds lines of code. But now it is a bit difficult, this is apparently a part of a class. And also we don't know what has been imported.
But I see you do
self.Date_label.setText(selectedDate.toString())
... to assign a value. And under show_date you are doing the same. My guess is that in show_date() you need to do:
self.Date_label.Text()
... and you will need to assign or return the result of that method.
Reply
#3
(Jul-03-2020, 09:36 AM)ibreeden Wrote: You are right in not showing hundreds lines of code. But now it is a bit difficult, this is apparently a part of a class. And also we don't know what has been imported.
But I see you do
self.Date_label.setText(selectedDate.toString())
... to assign a value. And under show_date you are doing the same. My guess is that in show_date() you need to do:
self.Date_label.Text()
... and you will need to assign or return the result of that method.

thanks for the suggestion ,I figure out the solution :
        date2= selectedDate.toString()
        self.Date_label.setText(date2)
hope others can benefit from sample above .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to set the calendar widget to current date scratchmyhead 4 7,164 May-11-2020, 08:27 PM
Last Post: scratchmyhead
  Tkinter calendar widget scratchmyhead 4 4,353 May-03-2020, 07:01 PM
Last Post: scratchmyhead
  [Tkinter] Retrieving a value from a calendar with a single click LagratteCchouette 4 9,678 Jan-26-2020, 04:36 PM
Last Post: LagratteCchouette

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020