如何在wxFrame上设置图标?

时间:2014-07-28 19:13:04

标签: wxpython wxwidgets

如何将图标(.ico文件)添加到wxFrame?

我正在查看docs,但无法提及icon

谢谢!

3 个答案:

答案 0 :(得分:7)

我在py2exe安装文件中尝试了这个设置,但它没有做任何事情:

windows = [
        {
            "script": "myscript.py",
            "icon_resources": [(1, "icon.ico")]
        }
    ],

但这最终起作用了。 Self是wx.Frame实例:

icon = wx.EmptyIcon()
icon.CopyFromBitmap(wx.Bitmap("icon.ico", wx.BITMAP_TYPE_ANY))
self.SetIcon(icon)

希望这有助于其他人。

答案 1 :(得分:3)

Phoenix wxpython:

TextPainter

经典wxpython:

import 'dart:ui';
import 'dart:typed_data';
import 'package:flutter/painting.dart';

const black = Color(0xff000000);
const white = Color(0xffffffff);

final identityTransform = new Float64List(16)
  ..[0] = 1.0
  ..[5] = 1.0
  ..[10] = 1.0
  ..[15] = 1.0;

TextPainter createTextPainter() {
  return new TextPainter(
    text: new TextSpan(
      text: '8',
      style: new TextStyle(
        color: black,
        fontSize: 200.0,
        fontFamily: "Roboto",
      ),
    ),
    textDirection: TextDirection.ltr,
  )..layout();
}

void drawBackground(Canvas canvas, Rect screen) {
  canvas.drawRect(
      screen,
      new Paint()
        ..color = white
        ..style = PaintingStyle.fill);
}

Picture createPicture() {
  final recorder = new PictureRecorder();
  final screen = Offset.zero & window.physicalSize;
  final canvas = new Canvas(recorder, screen);
  final offset = screen.center;
  final painter = createTextPainter();
  final bounds = offset & Size(painter.minIntrinsicWidth, painter.height);
  drawBackground(canvas, screen);
  painter.paint(canvas, offset);
  canvas.drawRect(
      bounds,
      new Paint()
        ..color = black
        ..style = PaintingStyle.stroke
        ..strokeWidth = 3.0);
  return recorder.endRecording();
}

Scene createScene() {
  final builder = new SceneBuilder()
    ..pushTransform(identityTransform)
    ..addPicture(Offset.zero, createPicture())
    ..pop();
  return builder.build();
}

void beginFrame(Duration timeStamp) {
  window.render(createScene());
}

void main() {
  window.onBeginFrame = beginFrame;
  window.scheduleFrame();
}

答案 2 :(得分:0)

wxWidgets 支持 平台无关 XPM 格式,技术上是一个扩展名为 .xpm 的头文件,包含一个字符串常量数组,例如

/* XPM */
static const char *icon_xnp1[] = {
/* columns rows colors chars-per-pixel */
"32 32 182 2 ",
"   c black",
".  c #0D0F13",
... };

有在线工具可以创建这种格式,例如 https://de.onlineconvert.com/icon-to-xpm .

图标由

设置
wxFrame frame;
...
frame.SetIcon(icon_xnp1))

部署隐式 wxIcon 构造函数

frame.SetIcon(wxIcon(icon_xnp1))) .