ฉันเป็นเชิดแพลตตินั่มทั้งหมดไปใช่และฉันรู้ว่ามีบางอย่างที่ฉันคิดถึงแต่ฉันไม่รู้ว่าสิ่งที่ฉันต้องเป็น PySide6 โปรแกรและฉันสร้างฟังก์ชันที่จะสร้างปฏิทินอยู่ใน QTableWidget ปฏิทินโดยใช้ศูนย์ควบคุม kde ในโมดูลภาษาไพธอน ทุกคนทำงานสบายดีแต่ปัญหามาตอนที่ฉันพยายามที่จะเพิ่มนำร่องปุ่มจะหาต่อไปแล้วเดือนก่อน: นี่คือของฉันฟังก์ชัน:
import sys
import os
import platform
import datetime as dt
import time
import calendar
from PySide6 import *
from PySide6 import QtGui
from PySide6 import QtWidgets
from PySide6 import QtCore
from PySide6.QtGui import QColor
from functools import partial
yy = int(dt.datetime.now().strftime("%Y"))
mm = int(dt.datetime.now().strftime("%m"))
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
global widgets
widgets = self.ui
# Calender generator
self.calender_gen(mm,yy)
def calender_gen(self, mm_g, yy_g):
# Creat table rows and columns
widgets.tableWidget_3.setRowCount(5)
widgets.tableWidget_3.setColumnCount(7)
# Table header labels
week_list = ["Sat","Sun","Mon","Tue","Wed","Thu","Fri"]
widgets.tableWidget_3.setHorizontalHeaderLabels(week_list)
# Start inserting days of the month into the table
row = 0
col = 0
for week in calendar.monthcalendar(yy_g,mm_g):
for day in week:
if day == 0:
widgets.tableWidget_3.setItem(row,col,QTableWidgetItem(" "))
else:
widgets.tableWidget_3.setItem(row,col,QTableWidgetItem(str(day)))
col += 1
row += 1
col = 0
print(mm_g,yy_g)
# Connect Buttons to function
widgets.pushButton_3.clicked.connect(partial(self.next_calendar_butt,mm_g,yy_g))
widgets.pushButton_2.clicked.connect(partial(self.prev_calendar_butt,mm_g,yy_g))
def next_calendar_butt(self,mm_new, yy_new):
mm_new += 1
if mm_new > 12:
mm_new = 1
yy_new += 1
widgets.tableWidget_3.setRowCount(0)
widgets.tableWidget_3.setColumnCount(0)
self.calender_gen(mm_new,yy_new)
def prev_calendar_butt(self,mm_g_new,yy_g_new):
mm_g_new -= 1
if mm_g_new == 0:
mm_g_new = 12
yy_g_new -= 1
widgets.tableWidget_3.setRowCount(0)
widgets.tableWidget_3.setColumnCount(0)
self.calender_gen(mm_g_new,yy_g_new)
ตอนที่ผมทำแอ๊ปปฏิทินแสดงอยู่ในโต๊ะเหมือนในภาพ ของภาพของส่วนติดต่อผู้ใช้แบบโต๊ะ
คอนโซลส่งออก ของคอนโซลรอยนิ้วมือ 112021
ตอนที่ฉันคลิกบน pushButton_3 สำหรับครั้งแรกคลิกมันทำงานตามปกติและรอยนิ้วมือ'122021'ในคอนโซล คอนโซลรอยนิ้วมือ 122021 แต่หลังจากที่ผมคลิกบนปุ่มเดียวกันอีกครั้งมันเริ่มจาก duplication:คอนโซลรอยนิ้วมือ'12202112022' คอนโซลรอยนิ้วมือ 12202112022 ถ้าฉัคลิกอีกครั้งมันรอยนิ้วมือ'12 2021 1 2022 1 2022 2 2022' เหมือนในภาพ ป้องภาพรายละเอียดที่นี่ กับทุกคลิกมันทำซ้ำมากกว่าที่มันควรจะพิมพ์เท่านั้นคนแถลงการณ์ผมก็ไม่ต่างกันหรอกe'22022'
ฉันพยายามที่จะย้ายไปที่ด้านล่างบรรทัดออกมาจาก calendar_gen ฟังก์ชัน()แต่ฉัน coudn ไม่องไปส่งค่าพารามิเตอร์แม้แต่หลังจากประกาศว่ากองโกลบอลตัวแปรและกำหนดพวกเขาไปที่พารามิเตอร์:
widgets.pushButton_3.clicked.connect(partial(self.next_calendar_butt,mm_g,yy_g))
widgets.pushButton_2.clicked.connect(partial(self.prev_calendar_butt,mm_g,yy_g))
ฉันพยายามจะทำอย่างนี้: ใน calendar_gen ฟังก์ชัน()ฉันประกาศโกลบอลและตัวแปรอบหมายให้พวกเขาต้องฟังก์ชันพารามิเตอร์เพื่อสร้างบางอย่างเหมือนเป็นโกลบอลพารามิเตอร์
global var_mm
global var_yy
var_mm = mm_g
var_yy = yy_g
แล้วในตอ init(ตัว)ฟังก์ชันฉันใส่พวกนั้น 2 บรรทัด:
def __init__(self):
widgets.pushButton_3.clicked.connect(partial(self.next_calendar_butt,var_mm,var_yy))
widgets.pushButton_2.clicked.connect(partial(self.prev_calendar_butt,var_mm,var_yy))
แต่มันไม่ได้ทำงานในคอนโซลมันรอยนิ้วมือ'112021'เมื่อฉันวิ่งแอพฯนั้นตอนที่ฉันคลิกบน pushButton_3 มันรอยนิ้วมือ'122021'และเมื่อคลิกอีกครั้งนะมันรอยนิ้วมือ'122021'อีกครั้งและดังนั้นอยู่ เหมือนกับคนอื่นปุ่มมันรอยนิ้วมือ'102021'อีกครั้งและอีกครั้ง