Creating a fixed background using tkinter - user-interface

I am using tkinter when and trying to set up a window with a background image. In some of the processes I have a frame that fills up with checkboxes so I created a scrollbar so the user can see all the options. The problem is the scroll bar also moves the background image of the canvas. Is there a way I can fix the image to not move or somehow move the frame by itself.
code is
def canvasScroll():
canvas = gui.createCanvas()
fFrame = gui.createNewFrame()
scrollbar = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand = scrollbar.set)
scrollbar.pack(side="right", fill="y")
canvas.pack(side="left", fill="both", expand= True)
canvas.create_window((150,50),window = fFrame, anchor='nw', tags = "frame")
gOb.change_canvas(canvas)
fFrame.bind("<Configure>", gui.scroll)
gOb.change_scrollbar(scrollbar)
gOb.change_frame(fFrame)
def createCanvas():
canvas = Canvas(root,height = _h, width = _w,highlightthickness = 0)
canvas.pack(side='top',fill='both',expand='yes')
canvas.create_image(-200,-200,image=bground,anchor='nw')
return canvas
def createNewFrame():
frame = Frame(root,height = _h, width = _w,background='white')
frame.pack()
return frame
Just to clear things up, these guys are all part of a class name gui and gOb is an object that hold several gui objects.

Here's one idea - it's kind of kludgy, but it would work. Every time the scrollbar scrolls, shift the background image's position so it appears to stay in the same place:
Tag your image so you can access it later:
canvas.create_image(-200,-200,image=bground,anchor='nw',tags="background")
# ^^^^^^^^^^^^^^^^^
Make your scrollbar call a function that you define:
scrollbar = Scrollbar(root, orient="vertical", command=scrollCallback)
Define your scroll callback:
def scrollCallback(*args):
canvas.yview(*args)
# Arrange for your background image to move so it appears to stay in the same position as the canvas scrolls.

Related

Remove white space at the bottom when moving tabs to the top in Xamarin.iOS

I need to create the tabbed menu as per Youtube's latest UI and show the menu at the top on Android and iOS.
The default behavior on Android is to show menu at the top so that's working fine.
On iOS I have created a custom render and I am using following code to change the position of the bar to the top:
UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
if (UIInterfaceOrientation.LandscapeLeft == orientation || UIInterfaceOrientation.LandscapeRight == orientation)
{
tabSize = 32.0f;
}
CGRect tabFrame = this.TabBar.Frame;
tabFrame.Height = tabSize;
tabFrame.Y = this.View.Frame.Y;
this.TabBar.Frame = tabFrame;
this.TabBar.ContentMode = UIViewContentMode.ScaleToFill;
// Set the translucent property to NO then back to YES to
// force the UITabBar to reblur, otherwise part of the
// new frame will be completely transparent if we rotate
// from a landscape orientation to a portrait orientation.
this.TabBar.Translucent = false;
this.TabBar.Translucent = true;
//this.TabBar.Translucent = false;
this.TabBar.SetNeedsUpdateConstraints();
My problem is that there is some white space at the bottom to compensate for the bar which is already moved to the top.
Does any one knows how to fix this?
This problem is also in following post but I am not able to find answer.
https://forums.xamarin.com/discussion/comment/226114/#Comment_226114

PySDL2: Renderer or Window Surface for handling colors and text?

My question concerns the sdl2.ext.Renderer mainly, and has to do with a problem I've encountered when trying to render sprites on a sdl2.ext.Window surface.
So right now, for coloring my background on an SDL2 Window, I make the following call:
White = sdl2.ext.Color(255,255,255)
class Background(sdl2.ext.SoftwareSpriteRenderSystem):
def __init__(self,window):
super(Background,self).__init__(window)
sdl2.ext.fill(self.surface,White)
This colors the surface of the Window with a white background. However, I also want to display text on the screen. This is done by creating a TextureSprite using the from_text method of the sdl2.ext.SpriteFactory class as follows:
Renderer = sdl2.ext.Renderer(W) # Creating Renderer
ManagerFont = sdl2.ext.FontManager(font_path = "OpenSans.ttf", size = 14) # Creating Font Manager
Factory = sdl2.ext.SpriteFactory(renderer=Renderer) # Creating Sprite Factory
Text = Factory.from_text("Unisung Softworks",fontmanager=ManagerFont) # Creating TextureSprite from Text
Renderer.copy(Text, dstrect= (0,0,Text.size[0],Text.size[1])) # Resizing the Texture to fit the text dimensions when rendered
The problem occurs when the event loop is run.
running = True
while running:
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running = False
break
if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
pass
Renderer.copy(Text, dstrect= (0,0,Text.size[0],Text.size[1]))
Renderer.present() # Problem 1
W.refresh() # Problem 2
return 0
Full Example Paste
When both Renderer.present() and W.refresh() are called, I get a flickering effect from the screen. This seems to be because the Renderer overwrites the White colored Window surface, which then gets colored over again by the Window.refresh() call. This then repeats, resulting in a flickering mess.
I would like to know what I can do to solve this problem? Should I even be using both Window.refresh() and the Renderer at the same time? Is there a way to let one render the other? (Renderer renders background for example). If anyone can help me out, that would be great.
The problem is that you are using Window.refresh() along with a SDL_Renderer and a SoftwareSpriteSystem with SDL_Texture objects.
As outlined in the PySDL2 docs, this is likely to break (since software surface buffers get mixed with hardware-based textures) and you should avoid it. If you want to color the window background, you should use Renderer.clear(White) instead of your Background class and call it before copying the text via Renderer.copy():
Renderer.clear(White)
Renderer.copy(Text, dstrect= (0,0,Text.size[0],Text.size[1]))
Renderer.present()
Do not forget to change the color for your FontManager. By default it uses a white text color, so you should change it to e.g. your Red color:
ManagerFont = sdl2.ext.FontManager(font_path = "OpenSans.ttf", size = 14, color=Red)

PopUp in Windows Phone 7

I want to use popUp element in windows phone (C#) to view a message on screen
I did the following:
popUpBanner = new Popup();
popUpBanner.HorizontalAlignment = HorizontalAlignment.Center;
popUpBanner.VerticalAlignment = VerticalAlignment.Center;
But the popup element appears in the top left of the screen .. not at the center
How can I solve this
In Windows Phone the Pop up is not a UserControl class. Instead of centering the popup you want to center the ui elements within the popup's child element...
To be more specific, I updated my code and hope it helps you.
First lets get the screen size(i.e. Width & Height)
var width = System.Windows.Application.Current.Host.Content.ActualWidth;
var height = System.Windows.Application.Current.Host.Content.ActualHeight;
Lets create a StackPanel, adding background color to it and re-sizing the StackPanel according to the device screen resolution.
StackPanel stackPanel = new StackPanel();
stackPanel.Background = new SolidColorBrush(Colors.Gray);
stackPanel.Height = height / 4;
stackPanel.Width = width / 2;
Finally Create a Popup and add it as a children to the StackPanel.
Popup Popup1 = new Popup();
stackPanel.Children.Add(Popup1);
ContentPanel.Children.Add(stackPanel);
Popup1.IsOpen = true;
You are done. Modify your StackPanel size according to your need, since you got the screen resolution here.

garbage text drawn on screen on tilting

Hi I have a nokia 5800 phone on which I was doing some pys60 ui programming. I used the below code to create the arrow. In short the draw() will draw the arrow onto the canvas surface. The canvas has redraw_callback and resize_callback hooked up to call draw() eventually. But on tilting I get some random text (garbage) output on the screen.
import appuifw
from appuifw import *
import e32
from graphics import *
def up(dummy):
appuifw.note(u'Button 1 Clicked', 'note')
def down(dummy):
appuifw.note(u'Button 2 Clicked', 'note')
appuifw.app.screen = 'normal'
def on_resize(dummy):
draw()
def on_redraw(dummy):
draw()
def on_exit():
global lock
lock.signal()
def draw():
global canvas
canvas.clear()
canvas.polygon((20,20,20,60,40,40,20,20), fill=(255,0,0), width=10)
canvas = appuifw.Canvas(resize_callback=on_resize, redraw_callback=on_redraw)
lock = e32.Ao_lock()
appuifw.exit_key_handler = on_exit
draw()
lock.wait()
Here is how it looks when I've held the phone straight up.
Here is how it looks when I've tilted it.
Note that the space that has the text (in landspace) is the size of the width minus the width it was when the orientation was portrait. Are you forgetting to resize the canvas to the landscape new dimentions?
It seems the text is the console output, check what is not being defined and whatever else is being output there.
appuifw.app.orientation = 'portrait'
or even:
appuifw.app.orientation = 'landscape'

building gui using wxpython

I added an image into a panel in my gui . I want this image to be fitted in the panel, where i wanna make its length as same as the panel legth .. How can i do this please ?
i did the following in my code ? so the image appeared at the top of the panel as what i want, but i wanna resize this image to increase its length .
class myMenu(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(900, 700))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour('#4f3856')
img = 'C:\Users\DELL\Desktop\Implementation\img1.jpg'
bmp = wx.Bitmap(img)
btmap = wx.StaticBitmap(panel, wx.ID_ANY, bmp, (0, 0))
If you want to scale the image you'll probably want to open it as a wx.Image rather than a wx.Bitmap. You can then scale it using the wx.Image's scale(self, width, height, quality) method http://www.wxpython.org/docs/api/wx.Image-class.html#Scale
The real problem is you want to get the image to resize every time the window does. That means you'll need to bind the wx.EVT_SIZE event to some method in your class (say onSize). Then every time onSize is called, you'll need to:
Find the current window size,
Scale the wx.Image to that size,
Convert it to a wx.Bitmap using wx.BitmapFromImage,
Call SetBitmap on your wx.StaticBitmap, passing the new bitmap.
See http://zetcode.com/wxpython/events/ for a basic introduction to event handling in wxPython, including an example with the wx.EVT_SIZE.

Resources