搜尋此網誌

2020年5月18日 星期一

How to read the screen resolution by python3.7


If we want to know the windows' screen resolution, we can use the win32api and win32con to get the value from windows.
The example as below.

import win32api, win32con

y = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
x = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)

print(x, ",", y)
The execution result:

2560 , 1080

Process finished with exit code 0









2020年5月15日 星期五

About the difference between os.exit () and sys.exit () in python

The sys.exit() the return code can be capture by caller, but os.exit() just end the process.

In the python documentation has below explain.
  • os.exit()

  • sys.exit()

2020年5月14日 星期四

How to create a requirement file of python project

For each project, we need a file that records the project's software package in the required format.
So we can use the freeze command to output the software package version.

The pip has command freeze that will list all software package version.
pip help message

We can use the freeze to export the requirement.txt.

The file will including the software package version.


How to install the software package in the new environment?


2020年2月16日 星期日

[Python] 練習



運算符描述
[] [:]下標,切片
**指數
~ + -按位取反, 正負號
* / % //乘,除,模,整除
+ -加,減
>> <<右移,左移
&按位與
^ |按位異或,按位或
<= < > >=小於等於,小於,大於,大於等於
== !=等於,不等於
is is not身份運算符
in not in成員運算符
not or and邏輯運算符
= += -= *= /= %= //= **= &= `^= >>= <<=`

複合運算example:
a  =  10 
b  =  3 
a  +=  b  #相當於:a = a + b 
a  *=  a  +  2  #相當於:a = a * (a + 2) 


練習:
Day1
"""練習1:華氏溫度轉換為攝氏溫度。提示:華氏溫度到攝氏溫度的轉換公式為:$C=(F - 32) \div 1.8$
"""
f = float(input('輸入華氏溫度:'))
c = (f-32) / 1.8print('輸入華氏溫度 %0.1f, 攝氏溫度 %0.1f' % (f,c))

Day2
# -*- coding: UTF-8 -*-"""英制单位英寸和公制单位厘米互换

1 mm = 0.03937 in
Version: 0.1
"""
value = float(input("Please input value:"))
unit = input("Is 'in' or 'mm'? ")

if unit == "mm":
    newvlaue = value * 0.03937    print(" %f mm == %f in" % (value, newvlaue))
else:
    newvalue = value / 0.03937    print(" %f in == %f mm" % (value, newvlaue))

PyDev console: starting.
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
runfile('D:/Python_project/Day1/Test.py', wdir='D:/Python_project/Day1')
Please input value:>? 500
Is 'in' or 'mm'? >? mm
 500.000000 mm == 19.685000 in



2018年10月8日 星期一

Python 筆記: 二維列表使用

筆記:

H_1 = [1, 11, 111]
H_2 = [2, 22, 222]
H_3 = [3, 33, 333]
H_4 = [4, 44, 444]
H_5 = [5, 55, 555]
H_6 = [6, 66, 666]

a = [H_1, H_2, H_3, H_4, H_5, H_6]

print(a[5][2])

output:
666



2013年10月16日 星期三

GTK於VS2010之配置

最近想來研究GTK,一個可以使用C語言來寫GUI
為了設置VS2010上的配置,不斷地出錯與爬文
終於千辛萬苦的成功了!!!
因網路上大多為大陸的相關資料,而簡體版VS與繁體VS翻譯有所落差
所以將其流程記錄下來,以供後用。
我的系統是win7、64位元、VS2010
以下為所進行流程

1. 第一步於官網 http://www.gtk.org/download/index.php下載
選擇對應系統進入,找尋 All-in-one bundle的部分下載,於此我下載的是2.22版


2. 解壓縮至文件夾

我的解壓縮後位置為"C:\gtk+-bundle_2.22.1-20101229_win64"


3. 添加環境變數
"開始" → "電腦" 按右鍵選 "內容"  → "進階系統設定" → "環境變數" 
於path中加入 "C:\gtk+-bundle_2.22.1-20101229_win64\bin",若之前還有其他位置
,則輸入";"做分隔。


4. VS配置

開一個新專案,於方案總管內對專案名稱點右鍵選擇 "屬性" 
4.1 於 "VC++目錄" 中的 "Include目錄"
加入 "C:\gtk+-bundle_2.22.1-20101229_win64" 中
include與其底下次一級的子資料夾
lib資料夾中的 glib-2.0\include 與 gtk-2.0\include
再於 "程式庫目錄" 中加入 "C:\gtk+-bundle_2.22.1-20101229_win64\lib"


4.2 於 "連結器" 中的 "輸入" 的"其他相依性" 輸入

"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gtk-win32-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gdk-win32-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\glib-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gobject-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gdk_pixbuf-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gthread-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\gmodule-2.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\pango-1.0.lib"
"C:\gtk+-bundle_2.22.1-20101229_win64\lib\intl.lib"


5 進行測試
#include "stdafx.h"
#include <gtk/gtk.h>  
#include <windows.h>
int main(int argc, char** argv)  
{  
 GtkWidget* window;  
 gtk_init(&argc, &argv);  
 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
 g_signal_connect(GTK_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);  
 gtk_widget_show(window);  
 gtk_main();  
 return 0;  



6. 顯示中文問題與關閉主控台之方法
http://www.cnblogs.com/hanxi/archive/2011/05/19/2051518.html所提供的函式,可解決中文顯示問題
函式為
char* T(char* str) { return g_locale_to_utf8(str, -1, 0, 0, 0); }
之後呼叫
T("中文") 即可

http://www.cnblogs.com/hanxi/archive/2011/05/03/2035587.html中也提供關閉主控台之方法
6.1
簡體版
进入属性设置窗口,修改:链接器->系统->子系统设为Windows(/SUBSYSTEM:WINDOWS)
繁體版為
進入屬性設置視窗,修改:連結器→系統→子系統設為Windows(/SUBSYSTEM:WINDOWS)
6.2
簡體版
再修改:链接器->高级->入口点设为mainCRTStartup
繁體版
再修改:連結器→進階→進入點設為mainCRTStartup
感謝涵曦提供的解決方案

PS 最後Run的時候,跳出需要zlib1.dll,從GTK資料夾裡找出來,丟到編譯好的程式資料夾中,就可以正常使用 



參考資料

1. http://www.gtk.org/download/win64.php
2. http://blog.csdn.net/zfpnuc/article/details/5646735
3. http://blog.sina.com.cn/s/blog_6adcb3530101dd5r.html
4. http://www.cnblogs.com/hanxi/archive/2011/05/19/2051518.html

2013年10月14日 星期一

C語言 字串相加

在做多圖像處理時,需要做檔名組成
通常我是使用 這個函式做組合
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* string_concat [字串相加]
 * 將 str1 與 str2 相加,並返回新的字串
 * */
char *string_concat(char *str1, char *str2) {
    // 計算所需的陣列長度
    int length=strlen(str1)+strlen(str2)+1;
 
    // 產生新的陣列空間
    char *result = (char*)malloc(sizeof(char) * length);
 
    // 複製第一個字串至新的陣列空間
    strcpy(result, str1);
    // 串接第二個字串至新的陣列空間
    strcat(result, str2);
 
    return result;
}


int main(){
    char *a="123456";
    char *b="abcde";
    char *c=string_concat(a,b);
    printf("%s\n",c);
 
    _getch();
    return 0;
}

函式取至 
http://jax-work-archive.blogspot.tw/2009/04/c_7407.html