1
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

I tried setting the background image of a window in wpf IronPython and I keep getting syntax errors.

william.eyidi
  • 2,315
  • 4
  • 27
  • 39
t chen
  • 11
  • 2

1 Answers1

1

You should use double \ in path names. And you don't need the intermediate Image control.

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

Or even shorter:

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