python语言中怎样可以居中打印

Python018

python语言中怎样可以居中打印,第1张

python语言中的可以居中打印的方法如下:

1、首先python语言的软件。

2、随后在右上角的设置中找到打印。

3、随后在python语言中的居中打印点击打开即可。

字符宽度本来就很难。这个是难题。因为字符宽度不一致。 通常我们的做法是这样子。

你先在后面的画板上画一个字符串,然后测量它的宽度。再根据测量得到的宽度正式在你想绘制的画板上绘。

这个测量也是用它的API实现的。不是自己用尺子量。

另外一个办法是手机上用的。 每个字体的每个字符的长宽都有精准的数据。做一个这样的数据库。然后绘制前计算一下,就可以居中了。

  以前写的,你看看是否有所帮助

def center_window(self,master,width_flag = 0.382,height_flag = 0.382):

      """

      窗口先隐藏到大小设置完成以后才恢复,主要原因是如果不这么做,会发生闪影现象。

      width_flag 和 height_flag 值在 (0,1) ,是定位目标左上角的坐标的权重值。

      都设置为 0.5 的话,则窗口居中。

      withdraw() 函数是隐藏窗口,deiconify() 函数是显示窗口。

      update() 函数是将前面原件摆放以后的窗口更新,以便获得摆放后窗口的自适配大小。

      """

      master.withdraw()

      master.update()

      current_window_width = master.winfo_width()

      current_window_height = master.winfo_height()

      screen_width = master.winfo_screenwidth()

      screen_height = master.winfo_screenheight()

      suitable_location_x = int((screen_width - current_window_width)*width_flag)

      suitable_location_y = int((screen_height - current_window_height)*height_flag)

      master.geometry('+{}+{}'.format(suitable_location_x,suitable_location_y))

      master.deiconify()