انجمنهای فارسی اوبونتو
کمک و پشتیبانی => برنامهسازی => نویسنده: دانیال بهزادی در 03 مهر 1388، 01:53 قظ
-
سلام. من مدتی قبل برای پروژه درس زبانهای برتامهنویسی زبان پایتون رو انتخاب کردم و در حین تحقیق خیلی به این زبان علاقهمند شدم و یه سری برنامههای کوچیکی هم باهاش نوشتم. با بررسیهای فراوان فهمیدم که به وسیله ابزار pygtk میشه با پایتون برنامههایی با واسط کاربری برای gnome ایجاد کرد. منتها تا الآن هر تلاشی از سوی من برای نصب pygtk با شکست مواجه شده. میدونم ممکنه یه کم سوالم مسخره باشه، اما ممکنه یکی مراحل کامل نصب pygtk رو روی اوبونتو ۹.۰۴ توضیح بده؟ پیشاپیش از حمایت شما ممنونم.
-
sudo apt-get install glade-3
-
سلام دوست عزیز
تا الآن هر تلاشی از سوی من برای نصب pygtk با شکست مواجه شده. میدونم ممکنه یه کم سوالم مسخره باشه، اما ممکنه یکی مراحل کامل نصب pygtk رو روی اوبونتو ۹.۰۴ توضیح بده؟
pygtk به صورت پیش فرض نصبه جیگر
python رو باز کن و بنویس
import pygtk
اگر هیچ خطایی رخ نداد و فقط به خط بعدی رفت مشکلی نیست در غیر این صورت بنویس تا بررسی بشه.
-
glade رو هم نصب کردم و برای طراحی رابط مشکلی ندارم. منتها تازه فهمیدم که مشکل از خود پایتونه. هیچ برنامهی گرافیکیای رو اجرا نمیکنه. چندتا سورس برنامه آماده از نت گرفتم، ولی یچکدوم کار نکرد
-
سلام
glade رو هم نصب کردم و برای طراحی رابط مشکلی ندارم. منتها تازه فهمیدم که مشکل از خود پایتونه. هیچ برنامهی گرافیکیای رو اجرا نمیکنه. چندتا سورس برنامه آماده از نت گرفتم، ولی یچکدوم کار نکرد
لطفا در ترمینال برنامه رو اجرا کنید و نام برنامه بعلاوه ی خروجی ترمینال رو بگذارید .
-
مثلا همون برنامه ماشین حساب خودتون به آدرس http://forum.ubuntu.ir/index.php?action=dlattach;topic=7755.0;attach=2294 رو وقتی که اجرا می کنم، نشانگر ماوس به شکل + در میآد و کاری انجام نمیده. وقتی که روی صفحه کلیک می کنم این رو مینویسه:
./Calculator.py: line 2: syntax error near unexpected token `'2.0''
'/Calculator.py: line 2: `pygtk.require('2.0')
و یه فایل به نام pygtk,math,string
ایجاد میکنه.
%!PS-Adobe-3.0
%%Creator: (ImageMagick)
%%Title: (pygtk,math,string
)
%%CreationDate: (Sat Oct 17 13:55:41 2009)
%%BoundingBox: 0 0 657 435
%%HiResBoundingBox: 0 0 657 435
%%DocumentData: Clean7Bit
%%LanguageLevel: 1
%%Orientation: Portrait
%%PageOrder: Ascend
%%Pages: 1
%%EndComments
%%BeginDefaults
%%EndDefaults
%%BeginProlog
%
% Display a color image. The image is displayed in color on
% Postscript viewers or printers that support color, otherwise
% it is displayed as grayscale.
%
/DirectClassPacket
{
%
% Get a DirectClass packet.
%
% Parameters:
% red.
% green.
% blue.
% length: number of pixels minus one of this color (optional).
%
currentfile color_packet readhexstring pop pop
compression 0 eq
{
/number_pixels 3 def
}
{
currentfile byte readhexstring pop 0 get
/number_pixels exch 1 add 3 mul def
} ifelse
0 3 number_pixels 1 sub
{
pixels exch color_packet putinterval
} for
pixels 0 number_pixels getinterval
} bind def
/DirectClassImage
{
%
% Display a DirectClass image.
%
systemdict /colorimage known
{
columns rows 8
[
columns 0 0
rows neg 0 rows
]
{ DirectClassPacket } false 3 colorimage
}
{
%
% No colorimage operator; convert to grayscale.
%
columns rows 8
[
columns 0 0
rows neg 0 rows
]
{ GrayDirectClassPacket } image
} ifelse
} bind def
/GrayDirectClassPacket
{
%
% Get a DirectClass packet; convert to grayscale.
%
% Parameters:
% red
% green
% blue
% length: number of pixels minus one of this color (optional).
%
currentfile color_packet readhexstring pop pop
color_packet 0 get 0.299 mul
color_packet 1 get 0.587 mul add
color_packet 2 get 0.114 mul add
cvi
/gray_packet exch def
compression 0 eq
{
/number_pixels 1 def
}
{
currentfile byte readhexstring pop 0 get
/number_pixels exch 1 add def
} ifelse
0 1 number_pixels 1 sub
{
pixels exch gray_packet put
} for
pixels 0 number_pixels getinterval
} bind def
/GrayPseudoClassPacket
{
%
% Get a PseudoClass packet; convert to grayscale.
%
% Parameters:
% index: index into the colormap.
% length: number of pixels minus one of this color (optional).
%
currentfile byte readhexstring pop 0 get
/offset exch 3 mul def
/color_packet colormap offset 3 getinterval def
color_packet 0 get 0.299 mul
color_packet 1 get 0.587 mul add
color_packet 2 get 0.114 mul add
cvi
/gray_packet exch def
compression 0 eq
{
/number_pixels 1 def
}
{
currentfile byte readhexstring pop 0 get
/number_pixels exch 1 add def
} ifelse
0 1 number_pixels 1 sub
{
pixels exch gray_packet put
} for
pixels 0 number_pixels getinterval
} bind def
/PseudoClassPacket
{
%
% Get a PseudoClass packet.
%
% Parameters:
% index: index into the colormap.
% length: number of pixels minus one of this color (optional).
%
currentfile byte readhexstring pop 0 get
/offset exch 3 mul def
/color_packet colormap offset 3 getinterval def
compression 0 eq
{
/number_pixels 3 def
}
{
currentfile byte readhexstring pop 0 get
/number_pixels exch 1 add 3 mul def
} ifelse
0 3 number_pixels 1 sub
{
pixels exch color_packet putinterval
} for
pixels 0 number_pixels getinterval
} bind def
/PseudoClassImage
{
%
% Display a PseudoClass image.
%
% Parameters:
% class: 0-PseudoClass or 1-Grayscale.
%
currentfile buffer readline pop
token pop /class exch def pop
class 0 gt
{
currentfile buffer readline pop
token pop /depth exch def pop
/grays columns 8 add depth sub depth mul 8 idiv string def
columns rows depth
[
columns 0 0
rows neg 0 rows
]
{ currentfile grays readhexstring pop } image
}
{
%
% Parameters:
% colors: number of colors in the colormap.
% colormap: red, green, blue color packets.
%
currentfile buffer readline pop
token pop /colors exch def pop
/colors colors 3 mul def
/colormap colors string def
currentfile colormap readhexstring pop pop
systemdict /colorimage known
{
columns rows 8
[
columns 0 0
rows neg 0 rows
]
{ PseudoClassPacket } false 3 colorimage
}
{
%
% No colorimage operator; convert to grayscale.
%
columns rows 8
[
columns 0 0
rows neg 0 rows
]
{ GrayPseudoClassPacket } image
} ifelse
} ifelse
} bind def
/DisplayImage
{
%
% Display a DirectClass or PseudoClass image.
%
% Parameters:
% x & y translation.
% x & y scale.
% label pointsize.
% image label.
% image columns & rows.
% class: 0-DirectClass or 1-PseudoClass.
% compression: 0-none or 1-RunlengthEncoded.
% hex color packets.
%
gsave
/buffer 512 string def
/byte 1 string def
/color_packet 3 string def
/pixels 768 string def
currentfile buffer readline pop
token pop /x exch def
token pop /y exch def pop
x y translate
currentfile buffer readline pop
token pop /x exch def
token pop /y exch def pop
currentfile buffer readline pop
token pop /pointsize exch def pop
/Times-Roman findfont pointsize scalefont setfont
x y scale
currentfile buffer readline pop
token pop /columns exch def
token pop /rows exch def pop
currentfile buffer readline pop
token pop /class exch def pop
currentfile buffer readline pop
token pop /compression exch def pop
class 0 gt { PseudoClassImage } { DirectClassImage } ifelse
grestore
showpage
} bind def
%%EndProlog
%%Page: 1 1
%%PageBoundingBox: 0 0 657 435
DisplayImage
0 0
657 435
12.000000
657 435
0
0
EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6EDE5D6
.....
B4B49CEBE2D1D7CAB0D0C1A4CFC0A3CFC0A3CFC0A3CFC0A3CFC0A3CFC0A3CFC0A3CFC0A3CFC0A3
D0C1A4D8CAB0EBE2D1
%%PageTrailer
%%Trailer
%%EOF
-
سلام
مشکل از این هست که شما برنامه رو به وسیله ی nautilus باز می کنید این کد رو به ابتدای فایل کد برنامه ی ماشین حساب اضافه کنید و بعد می تونید در nautilus با مثلا دابل کلیک برنامه رو اجرا کنید.
#!/usr/bin/env python
در ضمن بهتره به وسیله ی ترمینال به آدرس برنامه برید و بعد بنویسید :
python calculator.py
فکر نمیکنم دیگه مشکلی پیش بیاد .
موفق باشید انشاا...
-
سلام
میشه کمک کنید
من برای برنامه نویسی با C و کتابخونه GTK برنامه libgtk*-dev رو نصب می کردم وبعد برنامه رو توی فایل با پسوند c ذخیره وبا دستور کامپایل می کردم
حالا می خوام بدونم برای برنامه نویسی با python وکتابخونه gtk چه برنامه ی باید نصب کنم
و چطوری کامپایل کنم
باتشکر
-
توی C شما هدرها رو که پسوند h دارن include میکنید(این فایلها توی پکجیهای dev هستن مثلاً پکیج libgtk2.0-dev)
اما توی پایتون، شما ماژولهای پایتون رو import میکنید. این ماژولها معمولاً توی پکیجهایی هستن که اسمشون با عبارت -python شروع میشه. مثلاً پکیج python-gtk2
پس شما چه بخواید برنامههای PyGTK رو اجرا کنید، و چه بخواید خودتون برنامهٔ PyGTK بنویسید، باید پکیج python-gtk2 رو نصب کنید(که احتمالاً الآن روی سیستمتون نصب هست! و شما نیازی نیست چیزی نصب کنید)
توی C فرق داره. کاربرانی که میخوان فقط برنامه رو اجرا کنن نیازی ندارن پکیجهای dev رو نصب کنن(این پکیجها فقط برای کامپایل هست).
اما توی پایتون کامپایل وجود نداره، پایتون اسکریپتی هست.