本文整理汇总了Golang中github.com/mattn/go-gtk/gtk.NewButtonWithLabel函数的典型用法代码示例。如果您正苦于以下问题:Golang NewButtonWithLabel函数的具体用法?Golang NewButtonWithLabel怎么用?Golang NewButtonWithLabel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewButtonWithLabel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("GTK Notebook")
window.Connect("destroy", gtk.MainQuit)
notebook := gtk.NewNotebook()
for n := 1; n <= 10; n++ {
page := gtk.NewFrame("demo" + strconv.Itoa(n))
notebook.AppendPage(page, gtk.NewLabel("demo"+strconv.Itoa(n)))
vbox := gtk.NewHBox(false, 1)
prev := gtk.NewButtonWithLabel("go prev")
prev.Clicked(func() {
notebook.PrevPage()
})
vbox.Add(prev)
next := gtk.NewButtonWithLabel("go next")
next.Clicked(func() {
notebook.NextPage()
})
vbox.Add(next)
page.Add(vbox)
}
window.Add(notebook)
window.SetSizeRequest(400, 200)
window.ShowAll()
gtk.Main()
}
示例2: CreateActivatableDemo
func CreateActivatableDemo(vbox *gtk.VBox) {
action_entry := gtk.NewAction("ActionEntry",
"Button attached to Action", "", gtk.STOCK_INFO)
action_entry.Connect("activate", func() {
fmt.Println("Action clicked")
})
frame1 := gtk.NewFrame("GtkActivatable interface demonstration")
frame1.SetBorderWidth(5)
hbox2 := gtk.NewHBox(false, 5)
hbox2.SetSizeRequest(400, 50)
hbox2.SetBorderWidth(5)
button1 := gtk.NewButton()
button1.SetSizeRequest(250, 0)
button1.SetRelatedAction(action_entry)
hbox2.PackStart(button1, false, false, 0)
hbox2.PackStart(gtk.NewVSeparator(), false, false, 0)
button2 := gtk.NewButtonWithLabel("Hide Action")
button2.SetSizeRequest(150, 0)
button2.Connect("clicked", func() {
action_entry.SetVisible(false)
fmt.Println("Hide Action")
})
hbox2.PackStart(button2, false, false, 0)
button3 := gtk.NewButtonWithLabel("Unhide Action")
button3.SetSizeRequest(150, 0)
button3.Connect("clicked", func() {
action_entry.SetVisible(true)
fmt.Println("Show Action")
})
hbox2.PackStart(button3, false, false, 0)
frame1.Add(hbox2)
vbox.PackStart(frame1, false, true, 0)
}
示例3: main
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("webkit")
window.Connect("destroy", gtk.MainQuit)
vbox := gtk.NewVBox(false, 1)
entry := gtk.NewEntry()
entry.SetText("http://golang.org/")
vbox.PackStart(entry, false, false, 0)
swin := gtk.NewScrolledWindow(nil, nil)
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swin.SetShadowType(gtk.SHADOW_IN)
webview := webkit.NewWebView()
webview.Connect("load-committed", func() {
entry.SetText(webview.GetUri())
})
swin.Add(webview)
vbox.Add(swin)
entry.Connect("activate", func() {
webview.LoadUri(entry.GetText())
})
button := gtk.NewButtonWithLabel("load String")
button.Clicked(func() {
webview.LoadString("hello Go GTK!", "text/plain", "utf-8", ".")
})
vbox.PackStart(button, false, false, 0)
button = gtk.NewButtonWithLabel("load HTML String")
button.Clicked(func() {
webview.LoadHtmlString(HTML_STRING, ".")
})
vbox.PackStart(button, false, false, 0)
button = gtk.NewButtonWithLabel("Google Maps")
button.Clicked(func() {
webview.LoadHtmlString(MAP_EMBED, ".")
})
vbox.PackStart(button, false, false, 0)
window.Add(vbox)
window.SetSizeRequest(600, 600)
window.ShowAll()
proxy := os.Getenv("HTTP_PROXY")
if len(proxy) > 0 {
soup_uri := webkit.SoupUri(proxy)
webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
soup_uri.Free()
}
entry.Emit("activate")
gtk.Main()
}
示例4: accountWindow
func accountWindow() {
// window settings
window_account := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window_account.SetPosition(gtk.WIN_POS_CENTER)
window_account.SetTitle("Add Account")
// main container
container_main := gtk.NewVBox(false, 10)
container_user := gtk.NewHBox(false, 0)
container_pass := gtk.NewHBox(false, 0)
container_buttons := gtk.NewHBox(false, 5)
container_main.SetBorderWidth(10)
// username
user_label := gtk.NewLabel("Username")
user_entry := gtk.NewEntry()
// password
pass_label := gtk.NewLabel("Password")
pass_entry := gtk.NewEntry()
pass_entry.SetVisibility(false)
// login and cancel buttons
button_login := gtk.NewButtonWithLabel("Add")
button_cancel := gtk.NewButtonWithLabel("Cancel")
// login
button_login.Clicked(func() {
username := user_entry.GetText()
password := pass_entry.GetText()
profile, err := CreateProfile(username, password)
if err == nil && profile != nil {
println("[*] Login successful")
window_account.Destroy()
}
})
// cancel
button_cancel.Clicked(func() {
window_account.Destroy()
})
// add elements to containers
container_buttons.Add(button_login)
container_buttons.Add(button_cancel)
container_user.PackStart(user_label, false, false, 20)
container_user.PackEnd(user_entry, true, true, 1)
container_pass.PackStart(pass_label, false, false, 20)
container_pass.PackEnd(pass_entry, true, true, 1)
container_main.PackStart(container_user, false, false, 1)
container_main.PackStart(container_pass, false, false, 1)
container_main.PackStart(container_buttons, false, false, 1)
window_account.Add(container_main)
window_account.SetSizeRequest(350, 150)
window_account.SetResizable(false)
window_account.ShowAll()
}
示例5: main
func main() {
gtk.Init(nil)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("Hello GTK+Go world!")
window.SetIconName("gtk-dialog-info")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
gtk.MainQuit()
}, "foo")
vbox := gtk.NewVBox(false, 1)
button := gtk.NewButtonWithLabel("Hello world!")
button.SetTooltipMarkup("Say Hello World to everybody!")
button.Clicked(func() {
messagedialog := gtk.NewMessageDialog(
button.GetTopLevelAsWindow(),
gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO,
gtk.BUTTONS_OK,
"Hello!")
messagedialog.Response(func() {
messagedialog.Destroy()
})
messagedialog.Run()
})
vbox.PackStart(button, false, false, 0)
window.Add(vbox)
window.SetSizeRequest(300, 50)
window.ShowAll()
gtk.Main()
}
示例6: CreateGuiController
func CreateGuiController() *GuiController {
guiController := &GuiController{}
guiController.buttons = make([]*gtk.Button, 0)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetPosition(gtk.WIN_POS_CENTER)
window.SetTitle("GTK Go!")
window.SetIconName("gtk-dialog-info")
window.Connect("destroy", func(ctx *glib.CallbackContext) {
fmt.Println("got destroy!", ctx.Data().(string))
gtk.MainQuit()
}, "foo")
buttonsBox := gtk.NewHBox(false, 1)
black := gdk.NewColorRGB(0, 0, 0)
for i := 0; i < 8; i++ {
button := gtk.NewButtonWithLabel(fmt.Sprint(i))
button.ModifyBG(gtk.STATE_NORMAL, black)
guiController.buttons = append(guiController.buttons, button)
buttonsBox.Add(button)
}
window.Add(buttonsBox)
window.SetSizeRequest(600, 600)
window.ShowAll()
return guiController
}
示例7: buildList
func (g *Gui) buildList(vbox *gtk.VBox) {
frame := gtk.NewFrame("Device List")
framebox := gtk.NewVBox(false, 1)
frame.Add(framebox)
vbox.Add(frame)
g.Status = gtk.NewStatusbar()
vbox.PackStart(g.Status, false, false, 0)
g.Store = gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING)
treeview := gtk.NewTreeView()
framebox.Add(treeview)
treeview.SetModel(g.Store)
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Device", gtk.NewCellRendererText(), "text", 0))
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 1))
treeview.GetSelection().SetMode(gtk.SELECTION_SINGLE)
controls := gtk.NewHBox(true, 0)
g.Start = gtk.NewButtonWithLabel("Start Sync")
g.Start.Clicked(func() {
var iter gtk.TreeIter
var device glib.GValue
selection := treeview.GetSelection()
if selection.CountSelectedRows() > 0 {
selection.GetSelected(&iter)
g.Store.GetValue(&iter, 0, &device)
MainGui.notify("Start Writing On: " + device.GetString())
doWrite(device.GetString())
} else {
MainGui.notify("No Active Selection")
}
})
controls.Add(g.Start)
g.Recheck = gtk.NewButtonWithLabel("Rescan")
g.Recheck.Clicked(func() {
devices := SearchValid()
MainGui.Store.Clear()
for _, x := range devices {
MainGui.appendItem("/dev/hidraw"+strconv.FormatUint(x.SeqNum(), 10), x.SysAttrValue("product"))
}
MainGui.notify("Scanning Done")
})
controls.Add(g.Recheck)
framebox.PackStart(controls, false, false, 0)
}
示例8: main
func main() {
gtk.Init(nil)
win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
win.SetTitle("Goodbye, World!")
win.SetSizeRequest(300, 200)
win.Connect("destroy", gtk.MainQuit)
button := gtk.NewButtonWithLabel("Goodbye, World!")
win.Add(button)
button.Connect("clicked", gtk.MainQuit)
win.ShowAll()
gtk.Main()
}
示例9: main
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("Alignment")
window.Connect("destroy", gtk.MainQuit)
notebook := gtk.NewNotebook()
window.Add(notebook)
align := gtk.NewAlignment(0.5, 0.5, 0.5, 0.5)
notebook.AppendPage(align, gtk.NewLabel("Alignment"))
button := gtk.NewButtonWithLabel("Hello World!")
align.Add(button)
fixed := gtk.NewFixed()
notebook.AppendPage(fixed, gtk.NewLabel("Fixed"))
button2 := gtk.NewButtonWithLabel("Pulse")
fixed.Put(button2, 30, 30)
progress := gtk.NewProgressBar()
fixed.Put(progress, 30, 70)
button.Connect("clicked", func() {
progress.SetFraction(0.1 + 0.9*progress.GetFraction()) //easter egg
})
button2.Connect("clicked", func() {
progress.Pulse()
})
window.ShowAll()
window.SetSizeRequest(200, 200)
gtk.Main()
}
示例10: NewBiomeInfoEditor
func NewBiomeInfoEditor(biomes []BiomeInfo) *BiomeInfoEditor {
ed := &BiomeInfoEditor{
Dialog: gtk.NewDialog(),
biolist: newBiomeList(),
}
ed.SetModal(true)
vbox := ed.GetVBox()
btnHBox := gtk.NewHBox(true, 0)
resetBtn := gtk.NewButtonWithLabel("Reset to defaults")
resetBtn.Connect("clicked", ed.reset)
loadBtn := gtk.NewButtonWithLabel("Load from file ...")
loadBtn.Connect("clicked", ed.load)
saveBtn := gtk.NewButtonWithLabel("Save to file ...")
saveBtn.Connect("clicked", ed.save)
btnHBox.PackStart(resetBtn, true, true, 3)
btnHBox.PackStart(loadBtn, true, true, 3)
btnHBox.PackStart(saveBtn, true, true, 3)
vbox.PackStart(btnHBox, false, false, 3)
ed.biolist.SetBiomes(biomes)
vbox.PackStart(ed.biolist, true, true, 3)
editFrame := newBiomeEditFrame()
connectBiomeListEditFrame(ed.biolist, editFrame)
vbox.PackStart(editFrame, false, false, 3)
ed.AddButton("Cancel", gtk.RESPONSE_CANCEL)
ed.AddButton("OK", gtk.RESPONSE_OK)
ed.ShowAll()
return ed
}
示例11: main
func main() {
gtk.Init(&os.Args)
dialog := gtk.NewDialog()
dialog.SetTitle("number input")
vbox := dialog.GetVBox()
label := gtk.NewLabel("Numnber:")
vbox.Add(label)
input := gtk.NewEntry()
input.SetEditable(true)
vbox.Add(input)
input.Connect("insert-text", func(ctx *glib.CallbackContext) {
a := (*[2000]uint8)(unsafe.Pointer(ctx.Args(0)))
p := (*int)(unsafe.Pointer(ctx.Args(2)))
i := 0
for a[i] != 0 {
i++
}
s := string(a[0:i])
if s == "." {
if *p == 0 {
input.StopEmission("insert-text")
}
} else {
_, err := strconv.ParseFloat(s, 64)
if err != nil {
input.StopEmission("insert-text")
}
}
})
button := gtk.NewButtonWithLabel("OK")
button.Connect("clicked", func() {
println(input.GetText())
gtk.MainQuit()
})
vbox.Add(button)
dialog.ShowAll()
gtk.Main()
}
示例12: ShortTime
// ShortTime creates a GTK fullscreen window for the shorttime clients.
// No username/password required, only click 'start' button to log in
func ShortTime(client string, minutes int) (user string) {
// Inital window configuration
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
defer window.Destroy()
window.Fullscreen()
window.SetKeepAbove(true)
window.SetTitle("Mycel Login")
// Build GUI
frame := gtk.NewFrame("Logg deg på " + client)
frame.SetLabelAlign(0.5, 0.5)
var imageLoader *gdkpixbuf.Loader
imageLoader, _ = gdkpixbuf.NewLoaderWithMimeType("image/png")
imageLoader.Write(logo_png())
imageLoader.Close()
logo := gtk.NewImageFromPixbuf(imageLoader.GetPixbuf())
info := gtk.NewLabel("")
info.SetMarkup("<span foreground='red'>Dette er en korttidsmaskin\nMaks " +
strconv.Itoa(minutes) + " minutter!</span>")
button := gtk.NewButtonWithLabel("\nStart\n")
vbox := gtk.NewVBox(false, 20)
vbox.SetBorderWidth(20)
vbox.Add(logo)
vbox.Add(info)
vbox.Add(button)
frame.Add(vbox)
center := gtk.NewAlignment(0.5, 0.5, 0, 0)
center.Add(frame)
window.Add(center)
// Connect GUI event signals to function callbacks
button.Connect("clicked", func() {
gtk.MainQuit()
})
window.Connect("delete-event", func() bool {
return true
})
window.ShowAll()
gtk.Main()
return "Anonym"
}
示例13: newBiomeEditFrame
func newBiomeEditFrame() *biomeEditFrame {
frm := &biomeEditFrame{
Frame: gtk.NewFrame("Edit Biome"),
applyBtn: gtk.NewButtonWithLabel("Apply"),
idInput: gtk.NewEntry(),
snowLineInput: gtk.NewEntry(),
nameInput: gtk.NewEntry(),
colorInput: gtk.NewColorButton(),
}
frm.idInput.SetSizeRequest(40, -1)
frm.snowLineInput.SetSizeRequest(40, -1)
frm.idInput.Connect("changed", frm.unlockApply)
frm.nameInput.Connect("changed", frm.unlockApply)
frm.snowLineInput.Connect("changed", frm.unlockApply)
frm.applyBtn.SetSensitive(false)
vbox := gtk.NewVBox(false, 0)
hbox := gtk.NewHBox(false, 0)
frm.idInput.SetTooltipText("The data value of the Biome [0-255]")
frm.snowLineInput.SetTooltipText(fmt.Sprintf("Height (Y coordinate) at which snowfall starts (-1 or %d for no snowfall, 0 for always snowy)", mcmap.ChunkSizeY))
hbox.PackStart(gtk.NewLabel("Color:"), false, false, 0)
hbox.PackStart(frm.colorInput, false, false, 3)
hbox.PackStart(gtk.NewLabel("ID:"), false, false, 0)
hbox.PackStart(frm.idInput, false, false, 3)
hbox.PackStart(gtk.NewLabel("Snowline:"), false, false, 0)
hbox.PackStart(frm.snowLineInput, false, false, 3)
hbox.PackStart(gtk.NewLabel("Name:"), false, false, 0)
hbox.PackStart(frm.nameInput, true, true, 3)
vbox.PackStart(hbox, false, false, 0)
vbox.PackStart(frm.applyBtn, false, false, 3)
frm.Add(vbox)
frm.applyBtn.Connect("clicked", frm.doApply)
return frm
}
示例14: Init
// Init acts as a constructor for the Status window struct
func (v *Status) Init(client, user string, minutes int) {
// Initialize variables
v.client = client
v.user = user
v.minutes = minutes
v.warned = false
v.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
// Inital Window configuration
v.window.SetKeepAbove(true)
v.window.SetTitle(client)
v.window.SetTypeHint(gdk.WINDOW_TYPE_HINT_MENU)
v.window.SetSizeRequest(200, 180)
v.window.SetResizable(false)
// Build GUI
userLabel := gtk.NewLabel(user)
v.timeLabel = gtk.NewLabel("")
v.timeLabel.SetMarkup("<span size='xx-large'>" + strconv.Itoa(v.minutes) + " min igjen</span>")
button := gtk.NewButtonWithLabel("Logg ut")
vbox := gtk.NewVBox(false, 20)
vbox.SetBorderWidth(5)
vbox.Add(userLabel)
vbox.Add(v.timeLabel)
vbox.Add(button)
v.window.Add(vbox)
// Connect GUI event signals to function callbacks
v.window.Connect("delete-event", func() bool {
// Don't allow user to quit by closing the window
return true
})
button.Connect("clicked", func() {
gtk.MainQuit()
})
return
}
示例15: main
func main() {
gtk.Init(&os.Args)
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
window.SetTitle("GTK Table")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.NewScrolledWindow(nil, nil)
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
table := gtk.NewTable(5, 5, false)
for y := uint(0); y < 5; y++ {
for x := uint(0); x < 5; x++ {
table.Attach(gtk.NewButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.FILL, gtk.FILL, 5, 5)
}
}
swin.AddWithViewPort(table)
window.Add(swin)
window.SetDefaultSize(200, 200)
window.ShowAll()
gtk.Main()
}