-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtkinter_image.py
63 lines (48 loc) · 1.75 KB
/
tkinter_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
###############################################################
# © kenwaldek MIT-license
#
# Title: tkinter_image Version: 1.0
# Date: 26-12-16 Language: python3
# Description: tkinter inladen van image en text via menubar
#
###############################################################
from PIL import Image, ImageTk
from tkinter import *
class Window(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
Frame.tkraise(self)
self.master = master
self.init_window()
def init_window(self):
self.master.title('gui')
self.pack(fill=BOTH, expand=1)
# voegt een quit knop toe aan het frame
# quit_button = Button(self, text='quit', command=self.client_exit)
# quit_button.place(x=0, y=0)
menu = Menu(self.master)
self.master.config(menu=menu)
file = Menu(menu)
file.add_command(label='Exit', command= self.client_exit)
menu.add_cascade(label='File', menu=file)
edit = Menu(menu)
edit.add_command(label='Show image', command=self.show_img)
edit.add_command(label='Show txt', command=self.show_txt)
menu.add_cascade(label='Edit', menu=edit)
def client_exit(self):
exit()
def show_img(self):
load = Image.open('pic.png')
render = ImageTk.PhotoImage(load)
img = Label(self, image=render)
img.image = render
img.place(x=0, y=0)
def show_txt(self):
text = Label(self, text='hello world from kenny')
text.pack() # anders komt het niet op het scherm dus pack()
root = Tk()
root.geometry('400x300')
app = Window(root)
root.mainloop()