首页 > 编程知识 正文

python gui,python中文字体怎么设置

时间:2023-05-03 15:04:18 阅读:10679 作者:1366

参照报道

如何在Linux终端上输出彩色字符

2 .设置2. tput字体颜色

设置方法字符编码可设置字符的前景颜色和背景颜色

方法使用tput命令设置文字的前景颜色和背景颜色

总结了在工作脚本中设置字体颜色的脚本示例

设置方法字符编码可设置字符的前景颜色和背景颜色

样品

#! /jjdmla/bash

orgColor=`echo -e '33[0m ' `

redColor=`echo -e '33[31m ' `

echo 'an original font line '

echo ' $ { red color } aredfontline $ { org color } '

echo 'an original font line another '

方法使用tput命令设置文字的前景颜色和背景颜色

#! /jjdmla/bash

orgColor=`tput setaf 7`

redColor=`tput setaf 1`

echo 'an original font line '

echo ' $ { red color } aredfontline $ { org color } '

echo 'an original font line another '

方法设置字符编码设置字符的前景颜色和背景颜色

一.如何在外壳上实现

只需设置输出属性,即可输出彩色文本。 shell的某些属性:

33[0m关闭所有属性]

(033 )设定1m高亮度

33[4m下划线]

(033 )闪烁5米

(033 ) 7m翻转

(033 ) 8m消隐

(033 ) 30m至(33 ) 37m设置前景色

从(033 ) 40m到(33 ) 47m设定背景色

33[nA光标向上移动n行

33[nB光标下移n行

33[nC将数控光标向右移动n行

33[nD将nd光标向左移动n行

(33[y; 设定xH光标位置

(033 ) 2j清晰屏幕

33[K清除k光标到行尾的内容

33[s保存s光标位置

33[u撤消u光标位置]

(33[? 25l隐藏光标

(33[? 25h显示光标

------------- -请参阅

各数字表示的颜色如下。

字背景颜色范围:40----49

40:黑色

41:深红

42:绿色

43:黄色

44:蓝色

45:紫色

46:深绿色

47:白色

字的颜色:30----39

30:黑色

31:红色

32:绿色

33:黄

34:蓝色

35:紫色

36:深绿色

37:白色

示例: echo -e '33[34mHello,world!] (-e的作用是指导您设置输出属性。

恢复属性是默认值。 echo -e '33[0m ',

可以组合同类的多个设定项目,中间用分号()分隔。 如下所示。

echo -e '33[20; 1h(033 ) 1; 4; 34mHello,world(033[0m

二、用c语言实现方法

和壳牌的方法相似。 示例:

int color=34;

printf((((033 ) 20; 1h(033 ) 1; 4; %dmHello,world.33[0m ',color;

三.如何在Python上实现

color=34

print “33[20; 1h(033 ) 1; 4; %dHello,world.33[0m'%color

=====================================

=====================================

方法使用tput命令设置文字的前景颜色和背景颜色

原文来源于堆栈-溢出

使用

专用

tput sub-commands are discussed later.

Direct

Call tput as part of a sequence of commands:

tput setaf1;echo"this is red text"

Use ; instead of && so if tput errors the text still shows.

Shell variables

Another option is to use shell variables:

red=`tput setaf 1`green=`tput setaf 2`reset=`tput sgr0`echo"${red}red text ${green}green text${reset}"

tput produces character sequences that are interpreted by the terminal as having a special meaning. They will not be shown themselves. Note that they can still be saved into files or processed as input by programs other than the terminal.

Command substitution

It may be more convenient to insert tput's output directly into your echo strings using command substitution:

echo"$(tput setaf 1)Red text $(tput setab 7)and white background$(tput sgr 0)"

Example

The above command produces this on Ubuntu:

Foreground & background colour commands

tput setab[1-7]# Set the background colour using ANSI escapetput setaf[1-7]# Set the foreground colour using ANSI escape

Colours are as follows:

Num Colour #define R G B 0 black COLOR_BLACK 0,0,0 1 red COLOR_RED 1,0,0 2 green COLOR_GREEN 0,1,0 3 yellow COLOR_YELLOW 1,1,0 4 blue COLOR_BLUE 0,0,1 5 magenta COLOR_MAGENTA 1,0,1 6 cyan COLOR_CYAN 0,1,1 7 white COLOR_WHITE 1,1,1

There are also non-ANSI versions of the colour setting functions (setb instead of setab, and setfinstead of setaf) which use different numbers, not given here.

Text mode commands

tput bold# Select bold modetput dim# Select dim (half-bright) modetput smul# Enable underline modetput rmul# Disable underline modetput rev# Turn on reverse video modetput smso# Enter standout (bold) modetput rmso# Exit standout mode

Cursor movement commands

tput cup Y X# Move cursor to screen postion X,Y (top left is 0,0)tput cuf N# Move N characters forward (right)tput cub N# Move N characters back (left)tput cuu N# Move N lines uptput ll# Move to last line, first column (if no cup)tput sc# Save the cursor positiontput rc# Restore the cursor positiontput lines# Output the number of lines of the terminaltput cols# Output the number of columns of the terminal

Clear and insert commands

tput ech N# Erase N characterstput clear# Clear screen and move the cursor to 0,0tput el1# Clear to beginning of linetput el# Clear to end of linetput ed# Clear to end of screentput ich N# Insert N characters (moves rest of line forward!)tput il N# Insert N lines

Other commands

tput sgr0# Reset text format to the terminal's defaulttput bel# Play a bell

With compiz wobbly windows, the bel command makes the terminal wobble for a second to draw the user's attention.

Scripts

tput accepts scripts containing one command per line, which are executed in order before tputexits.

Avoid temporary files by echoing a multiline string and piping it:

echo-e"setf 7nsetb 1"|tput-S# set fg white and bg red

See also

See man 5 terminfo for the complete list of commands and more details on these options. (The corresponding tput command is listed in the Cap-name column of the huge table that starts at line 81.)

===============================================

=================================================

总结  工作脚本中设置字体颜色脚本 示例

代码如下:

#! /jjdmla/bash

set -o errexit

source /etc/profile

date_pattern_old='^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$'

date_pattern='^[0-9]{4}-((0([1-9]{1}))|(1[1|2]))-(([0-2]([0-9]{1}))|(3[0|1]))$'

#参数数量

argsnum=$#

#一些默认值

curDate=`date +%Y%m%d`

partitionDate=`date -d '-1 day' +%Y-%m-%d`

fileLocDate=`date -d '-1 day' +%Y-%m-%d`

#日志存放位置

logdir=load_hdfs_data_logs

function tips() {

echo "Usage : load_data_into_dmp_clearlog.sh [date]"

echo "Args :"

echo "date"

echo "date use this format yyyy-MM-dd , ex : 2018-06-02"

echo "============================================================"

echo "Example :"

echo "example1 : sh load_data_into_dmp_clearlog.sh"

echo "example2 : sh load_data_into_dmp_clearlog.sh 2018-06-02"

}

if [ $argsnum -eq 0 ] ; then

echo "No argument, use default value"

elif [ $argsnum -eq 1 ] ; then

echo "One argument, check date pattern"

arg1=$1

if ! [[ "$arg1" =~ $date_pattern ]] ; then

echo -e "33[31m Please specify valid date in format like 2018-06-02"

echo -e "33[0m"

tips

exit 1

fi

#echo $arg1 |tr "-" " "

dateArr=($(echo $arg1 |tr "-" " "))

echo "dateArr length is "${#dateArr[@]}

partitionDate=${dateArr[0]}-${dateArr[1]}-${dateArr[2]}

fileLocDate=${dateArr[0]}"-"${dateArr[1]}"-"${dateArr[2]}

else

echo -e "33[31m Not valid num of arguments"

echo -e "33[0m"

tips

exit 1

fi

if [ ! -d "$logdir" ]; then

mkdir -p $logdir

fi

echo ${partitionDate}

nohup hive -hivevar p_date=${partitionDate} -hivevar f_date=${fileLocDate} -f hdfs_add_partition_dmp_clearlog.hql >> $logdir/load_${curDate}.log

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。