gpt4 book ai didi

python - 使用 python 设置背景图像

转载 作者:太空宇宙 更新时间:2023-11-03 17:19:45 27 4
gpt4 key购买 nike

import wpf

from System.Windows import Application, Window,MessageBox
from Main import *
from Sign_Up import *

import System
from System.Windows.Controls import *
from System.Windows.Input import *
from System import Uri
from System.Windows.Media.Imaging import BitmapImage
from System.Windows.Media import ImageBrush

class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'Sign_In.xaml')
brush = ImageBrush()
image = Image()
image.Source = BitmapImage(Uri("C:\Users\Chen\Pictures\1-150511225359.jpg"))
brush.ImageSource = image.Source
self.SignUpGrid.Background = brush

我尝试在 wpf IronPython 中设置窗口的背景图像,但不断出现语法错误。

最佳答案

您应该在路径名中使用双\。而且您不需要中间的 Image 控件。

def __init__(self):
wpf.LoadComponent(self, 'Sign_In.xaml')
brush = ImageBrush()
brush.ImageSource = BitmapImage(Uri("C:\\Users\\Chen\\Pictures\\1-150511225359.jpg"))
self.SignUpGrid.Background = brush

或者更短:

def __init__(self):
wpf.LoadComponent(self, 'Sign_In.xaml')
self.SignUpGrid.Background = ImageBrush(BitmapImage(Uri(
"C:\\Users\\Chen\\Pictures\\1-150511225359.jpg")))

关于python - 使用 python 设置背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288839/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com