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
| import tkinter as Tk
from PySide import QtCore,QtGui
import sys
def imprime():
Appli=QtGui.QApplication(sys.argv)
editor = QtGui.QTextEdit()
cursor = editor.textCursor()
cursor.movePosition(QtGui.QTextCursor.Start)
textFormat = QtGui.QTextCharFormat()
textFormat.setFontPointSize(10)
alignCentrer= QtGui.QTextBlockFormat()
alignCentrer.setAlignment(QtCore.Qt.AlignCenter)
#premier tableau avec bordure
orderTableFormat = QtGui.QTextTableFormat()
orderTableFormat.setAlignment(QtCore.Qt.AlignCenter)
orderTable = cursor.insertTable(1,1, orderTableFormat)
orderFrameFormat = cursor.currentFrame().frameFormat()
orderFrameFormat.setBorder(1)
orderFrameFormat.setBorderStyle(QtGui.QTextTableFormat.BorderStyle.BorderStyle_Groove)
cursor.currentFrame().setFrameFormat(orderFrameFormat)
cursor = orderTable.cellAt(0, 0).firstCursorPosition().setBlockFormat(alignCentrer)
cursor = orderTable.cellAt(0, 0).lastCursorPosition()
cursor.insertText(' essai ',textFormat)
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertBlock()
cursor.insertBlock()
#second tableau sans bordure
orderTableFormat2 = QtGui.QTextTableFormat()
orderTableFormat2.setAlignment(QtCore.Qt.AlignLeft)
orderTable2 = cursor.insertTable(1,1, orderTableFormat2)
orderFrameFormat2 = cursor.currentFrame().frameFormat()
orderFrameFormat2.setBorder(0)
cursor.currentFrame().setFrameFormat(orderFrameFormat2)
cursor = orderTable2.cellAt(0, 0).firstCursorPosition().setBlockFormat(alignCentrer)
cursor = orderTable2.cellAt(0, 0).lastCursorPosition()
cursor.insertText(' essai ',textFormat)
dialog = QtGui.QPrintPreviewDialog()
dialog.paintRequested.connect(editor.print_)
dialog.exec_()
root = Tk.Tk()
btn = Tk.Button(root,text='imprime',command=imprime)
btn.pack()
root.mainloop() |